Live data from Hacker News

Code doesn’t have to be a mess

danielsieger.com

1–10 of 190 posts

Re: Code doesn’t have to be a mess

#4
post #2

Would be curious to know what strategies other people apply in order to keep complexity down over time!

Single source of truth is prob the biggest offender I see.

Same conceptual state gets represented in multiple variables or derived variables, and these must stay in sync. Very brittle

Re: Code doesn’t have to be a mess

#5
post #2

Would be curious to know what strategies other people apply in order to keep complexity down over time!

Unit Tests. If you can't write a unit test for it, it's too complicated and it's going to snowball quickly into a giant mess.

Unit tests, while good at promoting decoupling, can absolutely be a major driver of complexity, as it may break the code into far more units than what is reasonable.

Re: Code doesn’t have to be a mess

#6
There's a great section in The Practice of Programming where the book describes how you should structure your code to not just be structured nicely now, but to plan for the future; to structure it so that changes are easy, organized, and don't break anything.

It's not exhaustive but it's a powerful general idea and I always like introducing developers to it for the first time.

Re: Code doesn’t have to be a mess

#7
post #2

Would be curious to know what strategies other people apply in order to keep complexity down over time!

Unit Tests. If you can't write a unit test for it, it's too complicated and it's going to snowball quickly into a giant mess.

I love unit tests, but admit I have absolutely seen unnecessary complexity including complete classes and namespaces solely to enable testability in many cases.

It's a justifiable trade off for me, but I don't pretend that unit testing reduces complexity.

Re: Code doesn’t have to be a mess

#8
Ah the Unix philosophy. `man ssh' gives `ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-B bind_interface] [-b bind_address] [-c cipher_spec] [-D [bind_address:]port] [-E log_file] [-e escape_char] [-F configfile] [-I pkcs11] [-i identity_file] [-J destination] [-L address] [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address] [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]] destination [command]`

Re: Code doesn’t have to be a mess

#9
post #8

Ah the Unix philosophy. `man ssh' gives `ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-B bind_interface] [-b bind_address] [-c cipher_spec] [-D [bind_address:]port] [-E log_file] [-e escape_char] [-F configfile] [-I pkcs11] [-i identity_file] [-J destination] [-L address] [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address] [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]] destina…

Works quite well in conjunction with Googling "how do I do X in ssh stackoverflow".

Re: Code doesn’t have to be a mess

#10
post #2

Would be curious to know what strategies other people apply in order to keep complexity down over time!

Trust your tooling, and your repository. It's safe to delete if you still have a record of the way the code was before. Too often I see code that doesn't need to exist because someone is afraid to remove it. Modern IDEs are excellent at showing dependent code, and GIT and other source control tools are excellent at giving you freedom to remove things.

Oh, and have good testing in place to make sure you aren't breaking a required path that your IDE can't detect, obviously. No IDE in the world can detect "Oh, we still had one client on that old obsolete REST call and they are pissed"

Post reply on HN