Skip to main content

Some coding convention rules, working effectively with Legacy code

 https://softwareengineering.stackexchange.com/questions/133404/what-is-the-ideal-length-of-a-method-for-you

Method length should be 15 (soft limit).

We can do “testing to detect change.” In traditional terms, this is called regression testing. We periodically run tests that check for known good behavior to find out whether our software still works the way that it did in the past.

Let’s do a little thought experiment. We are stepping into a large function

that contains a large amount of complicated logic. We analyze, we think, we

talk to people who know more about that piece of code than we do, and then

we make a change. We want to make sure that the change hasn’t broken anything, but how can we do it? Luckily, we have a quality group that has a set of

regression tests that it can run overnight. We call and ask them to schedule a

run, and they say that, yes, they can run the tests overnight, but it is a good

thing that we called early. Other groups usually try to schedule regression runs

in the middle of the week, and if we’d waited any longer, there might not be a

Software Vise

vise (n.). A clamping device, usually consisting of two jaws closed or opened by a

screw or lever, used in carpentry or metalworking to hold a piece in position. The

American Heritage Dictionary of the English Language, Fourth Edition

When we have tests that detect change, it is like having a vise around our code. The

behavior of the code is fixed in place. When we make changes, we can know that

we are changing only one piece of behavior at a time. In short, we’re in control of

our work.

From the Library of Brian Watterson

ptg9926858

WORKING WITH FEEDBACK 11

Working with

Feedback

timeslot and a machine available for us. We breathe a sigh of relief and then go

back to work. We have about five more changes to make like the last one. All of

them are in equally complicated areas. And we’re not alone. We know that several other people are making changes, too.

The next morning, we get a phone call. Daiva over in testing tells us that

tests AE1021 and AE1029 failed overnight. She’s not sure whether it was our

changes, but she is calling us because she knows we’ll take care of it for her.

We’ll debug and see if the failures were because of one of our changes or someone else’s.

Does this sound real? Unfortunately, it is very real. 



We get ready to make our change, but we realize that it is pretty hard to figure out how to change it. The code is unclear, and we’d really like to understand it better before making our change. The tests won’t catch everything, so

we want to make the code very clear so that we can have more confidence in

our change. Aside from that, we don’t want ourselves or anyone else to have to

go through the work we are doing to try to understand it. What a waste of

time!


Unit testing is one of the most important components in legacy code work.

System-level regression tests are great, but small, localized tests are invaluable.

They can give you feedback as you develop and allow you to refactor with

much more safety


Testing in isolation is an important part of the definition of a unit test, but

why is it important? After all, many errors are possible when pieces of software

are integrated.


Note some issues with real project.

a. Team B (far away 4 time zone) have bad code practice + bad structure, design simple logic. This lead to code bad base. Missing logic, step (ie. Many SQL update run on the fly not documented or noted to any where in the code base or similar).
So "when start with legacy code, we have to test it." Within the knowledge of the system, we can. But this case we do not know or fully understanding the business logic (system behaviors). BA, owner (14 time zone away)... not documented it properly.

This lead to missing system behaviours / logic. And by common sense we think it is easy to capture (ie. many basic import/export CRUD task). But the way legacy code structure + mixed abnormally, special cases (old system have much of them) lead to 'simple task' become complicated.

2 ways: based on old code => run + test, compare data if missing/diff => trace + fix.
other way = rewrite then run / compare result => test + fix.

Both way still have issues: The INPUT change (ie. CSV input may be different of column, data type each time, float number etc...), so the OUTPUT also change a bit.
Without history of change (Git, or some kind of version control) we do not sure current code base work with future INPUT change / cases / special.

Comments

Popular posts from this blog

AWS Elasticache Memcached connection

https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/accessing-elasticache.html#access-from-outside-aws http://hourlyapps.blogspot.com/2010/06/examples-of-memcached-commands.html Access memcached https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/GettingStarted.AuthorizeAccess.html Zip include hidden file https://stackoverflow.com/questions/12493206/zip-including-hidden-files phpmemcachedadmin ~ phpMyAdmin or phpPgAdmin ... telnet mycachecluster.eaogs8.0001.usw2.cache.amazonaws.com 11211 stats items stats cachedump 27 100 https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/VPCs.EC.html https://lzone.de/cheat-sheet/memcached VPC ID Security Group ID (sg-...) Cluster: The identifier for the cluster memcached1 Creation Time: The time (UTC) when the cluster was created January 9, 2019 at 11:47:16 AM UTC+7 Configuration Endpoint: The configuration endpoint of the cluster memcached1.ahgofe.cfg.usw1.cache.amazonaws.com:11211 St...

Notes Windows 10 Virtualbox config, PHP Storm Japanese, custom PHP, Apache build, Postgresql

 cmd => Ctrl + Shift + Enter mklink "C:\Users\HauNT\Videos\host3" "C:\Windows\System32\drivers\etc\hosts" https://www.quora.com/How-to-create-a-router-in-php https://serverfault.com/questions/225155/virtualbox-how-to-set-up-networking-so-both-host-and-guest-can-access-internet 1 NAT + 1 host only config https://unix.stackexchange.com/questions/115464/how-to-properly-set-up-2-network-interfaces-in-centos-running-in-virtualbox DEVICE=eth0 TYPE=Ethernet #BOOTPROTO=dhcp BOOTPROTO=none #IPADDR=10.9.11.246 #PREFIX=24 #GATEWAY=10.9.11.1 #IPV4_FAILURE_FATAL=yes #HWADDR=08:00:27:CC:AC:AC ONBOOT=yes NAME="System eth0" [root@localhost www]# cat /etc/sysconfig/network-scripts/ifcfg-eth1 # Advanced Micro Devices, Inc. [AMD] 79c970 [PCnet32 LANCE] DEVICE=eth1 IPADDR=192.168.56.28 <= no eff => auto like DHCP #GATEWAY=192.168.56.1 #BOOTPROTO=dhcp BOOTPROTO=static <= no eff ONBOOT=yes HWADDR=08:00:27:b4:20:10 [root@localhost www]# ...

Rocket.Chat DB schema

_raix_push_notifications avatars.chunks avatars.files instances meteor_accounts_loginServiceConfiguration meteor_oauth_pendingCredentials meteor_oauth_pendingRequestTokens migrations rocketchat__trash rocketchat_cron_history rocketchat_custom_emoji rocketchat_custom_sounds rocketchat_import rocketchat_integration_history rocketchat_integrations rocketchat_livechat_custom_field rocketchat_livechat_department rocketchat_livechat_department_agents rocketchat_livechat_external_message rocketchat_livechat_inquiry rocketchat_livechat_office_hour rocketchat_livechat_page_visited rocketchat_livechat_trigger rocketchat_message rocketchat_oauth_apps rocketchat_oembed_cache rocketchat_permissions rocketchat_raw_imports rocketchat_reports rocketchat_roles rocketchat_room rocketchat_settings rocketchat_smarsh_history rocketchat_statistics rocketchat_subscription rocketchat_uploads system.indexes users usersSessions https://rocket.chat/docs/developer-guides/sc...