Live data from Hacker News

How to write unmantainable code (2015)

github.com

71–80 of 87 posts

Re: How to write unmantainable code (2015)

#71

Earlier quoted context omitted.

I've done big government contracts for many years as a consultant in Norway, and haven't really seen this. Guess it's because Java is so much better than those .NET monoliths ;) But seriously, I guess it depends on the maturity of those writing the tender / anbud. Too often they get bamboozled by big4 like consultancies (Accenture, Sopra Steria etc..) that act more like project managers and sales people than develope…

Thanks for the insider perspective. My experience as a dev in this sector is limited to interviewing for a few consultancies and noping out once I got a look at the code. But most massively public systems I interact with regularly seem to track with both our POVs. Of course the client side is definitely at fault too, for being naïve about these consulting firms. I wholly agree with you that big projects are not the w…

I was at NAV during their big transformation. The first year I was there, it was this huge billion kroner project. Probably more money was spent on business consultants speccing the project than developers. My company constantly complained about this way of working, that it will only lead to failure. Of course it did with missed deadlines etc, and eventually the huge project was scrapped.

They got a new director of IT, and managed to hire some hard-hitters internally as well. No longer listening to snake oil consultants, they finally started working the way we wanted. Smaller projects, if projects at all. More continuous deliveries. We got ownership all the way to production instead of just sending our code to some server people to deploy 4 times a year. All the code got open sourced etc. And us as consultants actually preferred this. Our company got paid essentially the same, but now we actually delivered value and worked with them instead of an uphill battle "against" them.

Re: How to write unmantainable code (2015)

#72
post #13

Earlier quoted context omitted.

I feel like every coder has to overdo it at least once to truly grok why it is a balancing act. And I think that oftentimes leads to the discovery that every best practice is a balancing act.

You're probably right on that. I now weigh my options to try to find a middle ground between impossible to change because it wasn't designed for change and impossible to change because it was designed for too many future use cases that will never happen.

IME, extensible code comes from thinking of possible extensions and then not getting in their way, which usually just means keeping it simple. Easy to say but hard to do.

Re: How to write unmantainable code (2015)

#73
post #67

The section on naming is amateur. Names like `fred` or 'asdf' are too obviously meaningless and wouldn't even pass a code review. You want names that do describe your code but badly . If your function reads policies from the DB, filters them and calculates some missing data, be sure to name the function 'readPolicies'. Nobody will look at that function when chasing a bug related to the filtering part! You may want to…

My favourite python function, get_data. Takes a dictionary called 'config'. Mutates it, sends it to another function called load_data. No docstrings anywhere.

We had stuff like that all over the place in the last React codebase I worked on. Naming things is hard, especially when you have to name them four times: once for the hook, once for the function that can potentially be called outside of the hook (non-react code), once for the API call, and once again for the graphql query.

Re: How to write unmantainable code (2015)

#74

My first job out of college, my boss and I took over some code that was written by two genius PhDs (one math, one physics - we were working in finance.) I noticed a variable (long word starting with z) used in a lot of places. Turns out it was the German word for "counter". It was my first hint that most of the backend codebase was written as a competition between the two of them to seem the smartest. On the front-en…

Ten levels of C++ templates and typedefs are a pretty good way of proving how smart you are and making the code completely opaque.

Re: How to write unmantainable code (2015)

#75

This is the way it seems to go in the public sector, at least here in Norway. 1. Get an n year government contract for some huge public IT overhaul. E.g building a new hospital journal system for a large region(this example is real, google "helseplatformen") 2. Spend years developing this huge proprietary .net monolith with a waterfall model, and minimal user interaction and testing during most of the contract. 3. Re…

Definitely true in Denmark too, their back in 2010s new tax IT system (skat-something) made a friend of mine who was sub-subcontracted from his 1-man company a wealthy man (wealthy as fully pay for small flat in central Prague, then for big flat a bit more off and then land & building a house a bit further away, only from income from this within few years, with 2 kids and wife not working).

When you get most of daily contractor fees directly, you easily end up with 15,000k$ net monthly income, working mostly remotely, in a country that had median monthly income below 1,000$.

Not that he worked hard or anything, frequently fridays looked like 'ok I am free give me some work' which almost never came. It was done on some ancient long dead weblogic/wslt things, stuff I can hack together in ie apache camel or similar in few afternoons (not 100% of it but core definitely yes).

Definitely a fault of government, no private company will come and say 'hey we can do it in 10% of the time / costs but we wont be using these big brand technologies (TM)'. Can't imagine there wasnt some big corruption too. IIRC prod launch was some major clusterfuck which filled newspapers for some time.

Re: How to write unmantainable code (2015)

#76
post #40

Earlier quoted context omitted.

The word with Z may be related to “zahlen” which is where Z as the letter commonly used to represent the integers comes from. [1] [1] https://en.wikipedia.org/wiki/Integer#History

I think it was a much longer word, and to be clear - neither of the dudes was German.

Maybe Zählvariable or something like that?

Re: How to write unmantainable code (2015)

#78
post #18

My favorite is when the codebase is so deeply buried in macros and headers that send you on a wild goose chase to find any actual code that it becomes much easier to just dump the binary in ida/binja. The source code can lie but at least the compiled binary directly does what it says

Having to track down macros across several files really annoys me as well. When I write macros in C, I place them just above the code where they are used and undefine them immediately after.

Using #undef is a big one that wasn't mentioned but oh god it is the ideal way to hide things. If you use it sparingly but in critical places of header files, especially to undef something potentially defined in three other headers, it becomes impossible to find the real substitution without reading the cc output

Re: How to write unmantainable code (2015)

#79

My first job out of college, my boss and I took over some code that was written by two genius PhDs (one math, one physics - we were working in finance.) I noticed a variable (long word starting with z) used in a lot of places. Turns out it was the German word for "counter". It was my first hint that most of the backend codebase was written as a competition between the two of them to seem the smartest. On the front-en…

Maybe this would be a good use for AI code generation. Reversable non-obfuscated obfuscated code. If you just obfuscate it it's pretty obvious what you're doing but if an AI can obfuscate it in a what that looks like something that is plausible that you could have written it you'd get away with it. Reversable so that you could undo it make updates and then reobfuscale.

Re: How to write unmantainable code (2015)

#80
Worked with some guys like this, probably doing it intentionally. One guy liked single-letter vars & derivatives thereof. For example all the following might appear in the same 100 lines of code: a, aa, a_, aa_, aa__, A, AA, A_, AA_.

Often these were crazy code forking paths like:

* a is a 1 liner which calls a_ or aa depending on a conditional.

* a_ then returns something or calls a__ depending on a conditional.

* aa calls aa_ or aa__ depending..

* A, AA, A_ and AA__ might be some global states or boolean flags or cmdline args or env vars read in which effect all the above..

Another favorite was to use the same noun in different cases for different types of things. For example:

* servers - a function you call which returns a list of servers

* servers_ - a subfunction called by servers

* SERVERS - a boolean global variable switch to enable functionality

* Servers - a variable containing the list of servers used by all of the above

I once asked him to explain the differences and there was no consistency. Sometimes all-caps was the function, sometimes all-caps was the boolean, sometimes lowercase, whatever.

The best was clearly someone forced him to put in comments under duress.

However he ONLY commented the obvious stuff, like-

getCmdline # gets the cmdline

Post reply on HN