News for hackers. Stuff that matters.
Re:Why bad scientific code beats code following "best practi... by jurschreuder on Saturday January 06, 2024 @01:38AM (#38889051)
This is so true I don't think I ever read something so true.

It's not even scientists vs software developers. It's people who are really into software development and clean code.

They say the program needs a total rewrite and proceed to add 20 layers of inheritance and spreading out every function over 8 files.

Ever since I make sure to repeat my mantra every week to developers:

How maintainable code is is measured in how many files you have to edit to add one feature.

Re:Why bad scientific code beats code following "best practi... by locallost on Saturday January 06, 2024 @04:16AM (#38889863)
To be honest it's mostly not their fault. Most people want to do the right thing and that's what they're taught. Doing things differently is frowned upon, and most people don't want to stick their neck out and say the emperor is naked.

Recently at work some people argued "things" (methods, classes, even files) should have a limit in size. I think that's valid thinking because you want to strive to having smaller components that you can reuse and compose, if you are able to do that. But what happened is that people started creating dozens of little files containing a function each and then importing those. To be it's obvious that this is now a lot worse because the complexity is still the same, just spread out across dozens of files. But most people were somehow convinced that they're "refactoring" and that they're doing best practices of keeping things small.

Re:Why bad scientific code beats code following "best practi... by danenania on Saturday January 06, 2024 @09:50AM (#38891841)
Yes, the main problem I've seen with focusing too much on length (of functions, files, or whatever else) is that people start spending tons of time rearranging the big messy drawer into n smaller messy drawers while totally avoiding the difficult work that needs to be done to actually organize the drawer(s).

All other things being equal, smaller functions and smaller files are a little bit better, but what really matters is architectural and conceptual complexity. Keeping those in check is all about using the right data structures (and doing painful refactors when you realize you've got the wrong ones). It has almost nothing to do with how files and functions are organized.

Re:Why bad scientific code beats code following "best practi... by logicchains on Saturday January 06, 2024 @02:12AM (#38889218)
>They say the program needs a total rewrite and proceed to add 20 layers of inheritance and spreading out every function over 8 files.

Anyone who in 2023 still thinks inheritance is a good idea for anything other than a few very specialised use-cases is not somebody who seriously cares about the craft of software development, not somebody who's put any effort to study programming theory and move beyond destructive 1990s enterprise Java practices. Widespread usage of inheritance inevitably makes code harder to reason about and refactor, as anyone who's compared code in Java to code for similar functionality in Rust or Go would see (both Rust and Go deliberately eschew support for inheritance due to the nightmares it can cause).

Re:Why bad scientific code beats code following "best practi... by dmz73 on Saturday January 06, 2024 @04:50AM (#38890026)
(Ab)use of any paradigm (I'll need a shower for using that word) can result in nightmares. Inheritance has its place and it is definitely useful in more than "few specialised cases". It can get out of hand and it can become a nightmare. Composition has its place and it is definitely not better than inheritance except in "few specialised cases". It can also result in nightmare, just wait till adoption of Rust and go is at the level of Java and C++ in enterprise environment and you will see. Writing clean and maintainable code should be the best practice and writing obfuscated code for performance and security should be reserved for "few specialised cases" but most developers and languages prefer the short and obfuscated to clear and (slightly) longer. RUst and go are perfect examples of why software development is an immature engineering discipline that favors "cool" and "terse" to clear and expressive...and no, C and C++ are not "good old times", they are old and slightly worse but not much worse, or I should clarify, go and rust and not much better because they still do not allow user (programmer) to express the intent clearly and instead force the reader of the code to sound like a person with severe speech impediment.
Re:Why bad scientific code beats code following "best practi... by Xeamek on Saturday January 06, 2024 @05:53AM (#38890351)
>Writing clean and maintainable code should be the best practice and writing obfuscated code for performance and security should be reserved for "few specialised cases"

Except, we can (fairly objectively) reason about performance and security, while 'clean code' and 'maintainability' are arbitrary, with vague guidelines at best.

Throwing out those first characteristics in name of the latter ones is just irrational.

(Not to even mention that performant and safe code still can be 'clean')

Re:Why bad scientific code beats code following "best practi... by danaris on Saturday January 06, 2024 @10:21AM (#38892127)
There's probably a Someoneorother's Law or Something Fallacy about this, because it's a common problem, especially among people who fancy themselves More Rational (and thus More Intelligent) than others:

You are assuming that the only things that matter are those that can be objectively measured (and measured simply and straightforwardly, with well-known metrics today).

Developer frustration, which will increase when having to deal with messy, unmaintainable code, is a real thing, even if it's harder to measure than performance and security. Not only does it create real stress and thus harm to the developers, it also slows development in ways that are going to be much less consistent and predictable than what's needed to write clean, maintainable code in the first place.

(Also, of course, there are at least some fairly well-accepted standards of clean, maintainable code, even if some aspects of those aren't entirely agreed on by everyone, and painting them as completely arbitrary, subjective things is just wrong.)

Re:Why bad scientific code beats code following "best practi... by Xeamek on Saturday January 06, 2024 @02:23PM (#38894453)
>You are assuming that the only things that matter are those that can be objectively measured.

No. Feelings do matter. But the problem is, what do You do when You have 2 people with conficliting feelings?

>Also, of course, there are at least some fairly well-accepted standards of clean code.

Are there though?

>even if some aspects of those aren't entirely agreed on by everyone, and painting them as completely arbitrary, subjective things is just wrong

Even if I grant You that there are some guidelines that are respected by overwhelming majority, that still doesn't prevent them from being arbitrary.

Re:Why bad scientific code beats code following "best practi... by danaris on Saturday January 06, 2024 @02:49PM (#38894708)
> But the problem is, what do You do when You have 2 people with conficliting feelings?

Hopefully, you try to work it out like adults, rather than just declaring that your way is the only rational way, and anyone else's feelings need to pound sand.

Furthermore, this isn't primarily about "feelings" in the sense of "this hurt my feelings;" this is primarily about adding unnecessary stress to developers' lives. Stress is something that is scientifically proven to increase susceptibility to diseases and cancers, and reduce lifespans, so it seems to me that this should be enough objective and rational evidence that we should be genuinely trying to reduce it.

> Are there though?

Well, I think most people would agree that putting an entire C file on one line is a pain to work with, even if skipping the "unnecessary" whitespace does save a little space.

And naming your variables alphabetically based on the order you use them in (eg, `int alpha`, `char bravo`, `std::string charlie` makes the code hard to maintain.

"Well, but that's just obvious stuff! No one would ever do that!"

I guarantee you someone would do just about any boneheaded thing you can imagine in programming unless told not to, either out of spite or because their brain really just works that way.

Just because you've made a bunch of assumptions about how people would or should code doesn't mean that those assumptions are any less arbitrary than anything else.

> that still doesn't prevent them from being arbitrary.

...But that's the thing. They're not. Just because they're not deeply well-researched to ensure that this particular set of coding standards measurably increases performance and decreases stress while maintaining code doesn't mean that maintainability is an arbitrary thing. It just means that it hasn't been adequately studied yet.

...or maybe it just means you haven't[0] looked[1] enough[2] yet, and the research that's out there hasn't yet had time to coalesce into any kind of industry-wide action.

Furthermore, it sounds very much like you're saying that coding standards like K&R, or C++ Core Guidelines, or PSR-2, are entirely arbitrary. They're clearly specified, they're written down and easy to reference, they codify plenty of aspects of coding style—but are all coding standards, no matter how well-respected, completely arbitrary?

[0] https://www.researchgate.net/publication/299412540_Code_Read...

[1] https://www.hindawi.com/journals/sp/2020/8840389/

[2] https://www.researchgate.net/publication/303870101_Software_...

Re:Why bad scientific code beats code following "best practi... by marcosdumay on Saturday January 06, 2024 @02:53PM (#38894756)
> There's probably a Someoneorother's Law or Something Fallacy about this

I once got your for a couple of hours researching the origin of that famous phrase "you can't improve what you don't measure", so I could blame it correctly.

The idea is quite old, of course, and popular to the 19th century rationalists. But the format people keep teaching around today seems to be a strawman created by Deming, at the 80's, in a speech about how stupid that idea is.

Anyway, I guess we need some Othersomeoneorother's Law about how you just can't make a good point against an idea without someone taking your point, preaching it unironically, and making a movement in support of the idea.

Re:Why bad scientific code beats code following "best practi... by Nevermark on Saturday January 06, 2024 @11:22AM (#38892684)
> Except, we can (fairly objectively) reason about performance and security, while 'clean code' and 'maintainability' are arbitrary, with vague guidelines at best.

Ok, how does one best reason about performance and security with messy unmaintainable code?

You barely need to try even shallow reasoning about a code base at all, before it's clean vs. messy, and maintainable vs. unmaintainable status will feel very objective and pertinent.

Re:Why bad scientific code beats code following "best practi... by Xeamek on Saturday January 06, 2024 @02:17PM (#38894376)
>Ok, how does one best reason about performance and security with messy unmaintainable code?

The same way one does it with 'clean' code: Using profiling tools. Security is a bit less straight forward, but still.

>will feel very objective.

Keyword: Feel. And while most people could probably agree on terrible code being terrible, the 'less terrible' the code is, the more this argument becomes a feeling. And then we hit up point where it's no longer possible to discuss things using objective arguments - how will a senior java developer, who is used to heavy OOP style coding reason with a senior C developer for whom such OOP heavy style is the oposite of 'clean'?

Ofcourse, the example is (too) simplistic, but even in this thread You have people arguing about "big functions" vs splitting things up. And unlike the performance, which You can alaways just point to the raw numbers, here You can't rely on any sorts of 'objectivity'

Re:Why bad scientific code beats code following "best practi... by Nevermark on Sunday January 07, 2024 @05:05AM (#38899965)
Certainly you can point to numbers re performance. But reasoning about performance is another thing if the code is a mess.

Messiness and unmaintainability does not scale. You can argue its not a completely objective thing to measure. That is true. And yet objectively, it really matters.

Not everything that is important comes with a clear number. Which is why experience and good judgement matter too. Two more things without numbers.

Re:Why bad scientific code beats code following "best practi... by Xeamek on Sunday January 07, 2024 @08:05AM (#38900878)
Again though: What do You do when someone thinks Your code is a mess, but You think it's good?
Re:Why bad scientific code beats code following "best practi... by Nevermark on Thursday January 11, 2024 @08:29PM (#38962327)
What kind of question is that?

It is impossible to answer without all the details of the situation. Different situations will have completely different answers. Who, what, where, how, when, why, ...?

Re:Why bad scientific code beats code following "best practi... by chongli on Saturday January 06, 2024 @05:29AM (#38890234)
The problem with inheritance is that no one seems to know where to use it best. Everyone just goes by feel and feelings frequently turn out to be wrong.

Composition is nice because it’s very simple and we can understand it mathematically. If you’re trying to understand inheritance mathematically then you’re basically left with using it only for algebraic structures (groups and rings and fields and vector spaces). But then you don’t really need inheritance there if you just have plain types and operator overloading.

Re:Why bad scientific code beats code following "best practi... by Nursie on Saturday January 06, 2024 @05:50AM (#38890331)
Operator overloading leads to less readable, maintainable code IMHO, because you have to go off and figure out if the operator means a special thing in a given context.

Certainly adds to complexity in C++.

Re:Why bad scientific code beats code following "best practi... by chongli on Saturday January 06, 2024 @06:04AM (#38890401)
It works well when you stick to math and follow mathematical laws. Overloading the addition operator to allow you to add two vectors is great, as long as you make sure you don’t break the laws of vector addition in your vector space.

Overloading addition to mean something else entirely? That’s a problem!

It would be great if type systems could allow us to set up these laws and enforce them at compile time, but then you go down the whole rabbit hole of automated theorem proving.

Re:Why bad scientific code beats code following "best practi... by roenxi on Saturday January 06, 2024 @05:37AM (#38890261)
Mmm. Maybe lets stop and address the question of "what are the key properties of inheritance?". Because I haven't seen a single use for it in maybe a decade or so and I'm not sure what it is you think you're defending.

Usually what people want is an interface; ie, a somewhat generic way of saying "this thing knows how to draw itself", "this thing supports printing" or "this thing can fizzle wuzzles like all the other wuzzle fizzlers". That is essential to coding.

But Java style inheritance carries a lot of baggage in excess of that; and some of it is just bad news. In practice it is a brittle assumption that a Foo is also and always a precise superset of Bar. And usually when that is true the relationship is so shallow having a dedicated concept of inheritance is wasteful, it may as well be an interface and a shared file of code.

TLDR; Inheritance is too many ideas mixed together; most useful and a couple bad. It is a better idea to present the different facets of inheritance to be selected a la carte. Mumble mumble Rich Hickey talks.

Re:Why bad scientific code beats code following "best practi... by whstl on Saturday January 06, 2024 @10:15AM (#38892070)
Yep. Inheritance is 3 or 4 different features in a trenchcoat, and most of them are bad.

Interfaces are good.

Method overloading for specialization or for creating mini-DSLs (Template Method pattern) is often problematic and is better replaced by composition, or by having the "overloaded" methods in a separate class.

Implementation Inheritance is certainly the worst form of "code reuse", and there's a reason people recommend composition over it since the 90s.

Using it for hierarchies (Dog inherits from Mammal, Mammal inherits from Animal) is just terrible and a joke at this point.

Re:Why bad scientific code beats code following "best practi... by sidlls on Saturday January 06, 2024 @07:37AM (#38890938)
Rust and Go both provide features to implement code in an OO-ish way: traits and interfaces. I just code in Rust as a hobby but I code in go professionally. The go codebases I work on at work are bloated messes of abstractions and duck typing, often meant to enforce some absurd standard of unit-testing. They can easily be as bad as any "enterprise Java" stereotype you wish to invoke.
Re:Why bad scientific code beats code following "best practi... by noobermin on Saturday January 06, 2024 @02:21PM (#38894435)
I hate to say this but this attitude of "it's 2023, inheritance is so 2008" is telling. How do you know the attitudes regarding best practices today are not going to be as bad as 20 layers of inheritance?
Re:Why bad scientific code beats code following "best practi... by o11c on Saturday January 06, 2024 @01:56AM (#38889130)
Wrong.

How maintainable code is is measured in how well you know where to change something, and how certain you are that it did the right thing without side effects.

The fatal error of the linked article is that bad scientific code often suffers from correctness problems - not just theoretical concerns, but the "negates the main point of this paper" kind of thing.

Re:Why bad scientific code beats code following "best practi... by thriftwy on Saturday January 06, 2024 @02:18AM (#38889248)
What if a new person takes your place and they do not know it and are not certain in anything?
Re:Why bad scientific code beats code following "best practi... by o11c on Saturday January 06, 2024 @02:31AM (#38889316)
That's how you measure job security, which is a slightly different concept than maintainability.
Re:Why bad scientific code beats code following "best practi... by skydhash on Saturday January 06, 2024 @08:46AM (#38891370)
When you hire a new person, there is usually some transfer of knowledge. Based on the above definition such transfer should be quick assuming that the person knows the platform and dependencies. A long time explaining the code is an indicator of needlessly complicated code
Re:Why bad scientific code beats code following "best practi... by erhaetherth on Saturday January 06, 2024 @01:50AM (#38889101)
That's a slippery mantra. I can see putting everything in one file.
Re:Why bad scientific code beats code following "best practi... by jampekka on Saturday January 06, 2024 @04:16AM (#38889864)
Everything in one file can be good organization for many even relatively large projects.
Re:Why bad scientific code beats code following "best practi... by Exoristos on Saturday January 06, 2024 @02:00AM (#38889146)
Am I missing something? Opening files is not my most intensive work as a developer.
Re:Why bad scientific code beats code following "best practi... by querez on Saturday January 06, 2024 @02:06AM (#38889191)
It's a decent measure of complexity: It's not that "opening files" themselves is work-intensive. But having a lot of files smells of overengineered code. One long, yet simple function has less cognitive overhead than spreading the function across multiple classes or functions or call hierarchies (themselves spread over multiple files).
Re:Why bad scientific code beats code following "best practi... by bobmaxup on Saturday January 06, 2024 @02:12AM (#38889221)
> One long, yet simple function has less cognitive overhead than spreading the function across multiple classes or functions or call hierarchies

Not if you are encapsulating and naming effectively...

Why read 100 lines when you can read 20 and find concerns in one routine you are concerned with?

Function calls can be expensive. However, optimization can come whenever you need it, and if what you need is one call vs 5, it is trivial to move that code back into a single routine.

Re:Why bad scientific code beats code following "best practi... by thorncorona on Saturday January 06, 2024 @02:29AM (#38889306)
I like long simple functions because it makes them easy to reason about when debugging.

Rarely does having more functions solve “does this do what I expect.”

Re:Why bad scientific code beats code following "best practi... by bobmaxup on Saturday January 06, 2024 @03:16AM (#38889570)
Maybe it boils down to how well you are able to navigate a code base.

With a full-featured language specific IDE, it is very easy to navigate through even complicated spaghetti. It makes debugging call traces simple, with a GUI.

However, many other file viewers and editors make this much more complicated, and it can be frustrating to follow code that is making heavy use of modularization.

If you are grepping your way through a deeply modular code base it can quickly become difficult to keep track of anything.

Re:Why bad scientific code beats code following "best practi... by phkahler on Saturday January 06, 2024 @04:29AM (#38889928)
>> With a full-featured language specific IDE, it is very easy to navigate through even complicated spaghetti.

If you need a fancy IDE to navigate around code in order to understand it, that might be crappy or poorly organized code.

Not a dig at nice IDEs, just code that requires one to navigate and understand.

Re:Why bad scientific code beats code following "best practi... by chongli on Saturday January 06, 2024 @05:38AM (#38890274)
Yeah. This is one of those hammer cases. If you’ve got a fancy IDE then the temptation is to use it. Similar to the issue of game programmers being given top of the line gaming PCs with frequent upgrades. They then struggle to understand why the game they just released runs like crap on most people’s modest computers.
Re:Why bad scientific code beats code following "best practi... by bobmaxup on Saturday January 06, 2024 @06:44PM (#38896794)
Not many people can understand a very large code base without taking notes, using an IDE, or similar tooling.

> Not a dig at nice IDEs, just code that requires one to navigate and understand

A nice IDE helps you reason about code, no matter what the underlying architecture is. That is why there is a market for them.

Re:Why bad scientific code beats code following "best practi... by oivey on Saturday January 06, 2024 @04:41AM (#38889984)
> Not if you are encapsulating and naming effectively...

No, and this is one of the reasons inheritance has lost popularity. Splitting some functionality across many files adds significantly to the cognitive load of figuring out what code is actually even running. After you trace that information out, you need to keep it all straight in your head while debugging whatever you’re working on. That’s even more problematic when you’re debugging, which implies you already don’t really understand what the program is doing.

And that’s in the case where things are named well. When they’re inevitably accidentally named in confusing or incorrect ways that can contribute to the bug itself and cause the code to be even more confusing.

Extreme levels of encapsulation has its own issues when, actually, the original author is wrong and you really do need some public access to some member. No one writing code is clairvoyant, so excessive encapsulation is common.

Re:Why bad scientific code beats code following "best practi... by rileymat2 on Saturday January 06, 2024 @05:24AM (#38890205)
> Splitting some functionality across many files adds significantly to the cognitive load of figuring out what code is actually even running.

This is the crux, if your goal is to figure out what code is running, if you can keep the program in your head, if you have small simple programs splitting things up is harmful.

But there is this murky line, different for everyone, and even different for the same person from day to day, where even with the best intent, no matter how good you are, you can't keep the program in your head.

At that point, you need to give up the idea that you can. Then you change perspective and see things in chunks, split up, divide and conquer, treat portions as black boxes. Trust the documentation's, pre and post conditions. Debugging becomes verifying those inputs and returns; only diving into the code of that next level when those expectations are violated.

Re:Why bad scientific code beats code following "best practi... by Xeamek on Saturday January 06, 2024 @06:00AM (#38890376)
But at some point you HAVE to be able to look at the program from above. If you abandon the hope of understanding the code in the bigger scope, how can you ever meaningfully modify it? (Ie add a big feature and not just tweak some small parameters)
Re:Why bad scientific code beats code following "best practi... by rileymat2 on Saturday January 06, 2024 @06:14AM (#38890455)
The rather unsatisfying answer, is it depends.

It depends on the change. It depends on the code organizational structures. It depends on the consistency of the code. It depends on the testing setup. It depends on the experience of the person changing it. It depends on the sensitivity of the functionality. It depends on the team structures.

Re:Why bad scientific code beats code following "best practi... by whstl on Saturday January 06, 2024 @10:55AM (#38892429)
There is however one reason that trumps them all: the actual reason the code was split.

Separating the code of your SQL server, HTTP server, Crypto Library, Framework, Standard Library, from your CRUD code is perfectly fine, and people understand this concept well, and even the most fervent anti-Clean-Code person won't complain about this separation existing.

But there is a good reason we separate those things from our CRUD codebase: it's because they can function separately fine, they're reusable, they're easy to isolate/reproduce problems, and they're at a totally different abstraction level.

The problem is separating code from the same level of abstraction, such as breaking a business logic class into many for mainly aesthetic reasons, such as method/class/module length, or to avoid having comments in the code (again as recommended by Clean Code), things that people are mentioning here in this thread.

EDIT: As someone said above, "20 files with 20 functions each does not cause high cognitive load, if the scope of each file and each function makes sense". In the end it's not the length or the number of methods/classes that matter, but how well separated they are. Having hard rules does not automatically make for good code, and it's often quite the opposite.

Re:Why bad scientific code beats code following "best practi... by rileymat2 on Saturday January 06, 2024 @06:35AM (#38890577)
One last thing to consider, if you are writing little a CRUD app, it can be very simple, you can keep it in your head.

However, Can you?

You are using black box code from a web server, a sql database, the operating system, crypto libraries, and a ton more; You don't dive into that source code except in extraordinary circumstances, if you even can. In a large program, you end up treating code owned by you or your company as the same way.

In this scenario you are still making large meaningful changes by focusing on the level of abstraction you are at.

Re:Why bad scientific code beats code following "best practi... by chongli on Saturday January 06, 2024 @04:44AM (#38890003)
Not if you are encapsulating and naming effectively...

Encapsulation is hard and a lot of what people call encapsulation isn’t. For example, taking a global variable and moving it to a class is not encapsulation. You have to actually do the hard work of removing the dependency on global shared state. Just changing everything to mutate the new global through an accessor to a “god” object that gets passed everywhere is accomplishing nothing at all. Worse than nothing, you’re complexifying without fixing the root problem: global mutable state.

Re:Why bad scientific code beats code following "best practi... by whstl on Saturday January 06, 2024 @11:01AM (#38892485)
It's funny how Singletons became such a meme pattern, and how about 80% of people in interviews only know about it when asked about patterns.

A cleverly-named way of disguising global mutable state does not make it better.

Re:Why bad scientific code beats code following "best practi... by whstl on Saturday January 06, 2024 @10:42AM (#38892311)
> "Not if you are encapsulating and naming effectively..."

When you only have to superficially skim the code, that works.

If there are incorrect abstractions, such as logging, transaction logic or manual error handling mixed with "well named function calls", then it is already very problematic even to skim.

If you have to debug, it quickly becomes torture. Especially if state is involved and shared between multiple methods or classes.

If you have to reimplement the code: you're probably fucked.

Re:Why bad scientific code beats code following "best practi... by __loam on Saturday January 06, 2024 @02:02AM (#38889157)
Adding indirection makes code less maintainable.
Re:Why bad scientific code beats code following "best practi... by Jtsummers on Saturday January 06, 2024 @02:11AM (#38889215)
> Adding indirection makes code less maintainable.

This is why I hated Fortran (77 in particular) as an applications language (for tasks like scientific computing people seemed to use saner portions of it). Computed go tos were the bane of my existence.

Re:Why bad scientific code beats code following "best practi... by naasking on Saturday January 06, 2024 @11:54AM (#38892958)
That's not correct as an unqualified statement. Sometimes indirection adds exactly the flexibility you need and that would otherwise require duplication (like generic collections/containers).

The more correct statement is that using more or less indirection than you need makes code less maintainable.

Re:Why bad scientific code beats code following "best practi... by canpolat on Saturday January 06, 2024 @01:51AM (#38889108)
Working with a 300 line method is not fun, believe me. Everything is in one place and you don't have to change many files, yes, but due to the cognitive load, it's so much more effort to maintain it.
Re:Why bad scientific code beats code following "best practi... by __loam on Saturday January 06, 2024 @02:04AM (#38889172)
There's a happy middle path here I think. Long functions are hard to grok. Spreading the logic across 20 files also increases cognitive load. There's a balance to strike.
Re:Why bad scientific code beats code following "best practi... by galaxyLogic on Saturday January 06, 2024 @02:32AM (#38889321)
Right, but the article seems to imply that all code should be in a single file.

It seems the author indeed is not a SW Engineer and thus does not really grok the benefit of "modules".

This of course depends on the size of the program. Small program "fits" into a single module.

And I think that scientific programs are basically small and simple because they don't typically need to deal with user-interaction at all, they just need to calculate a result.

Further I think scientific programs rely heavily on existing libraries, and writing a program that relies heavily on calls to external libraries produces simple, short programs.

Scientists produce science, engineers produce code-libraries.

Re:Why bad scientific code beats code following "best practi... by cjfd on Saturday January 06, 2024 @04:15AM (#38889857)
"It seems the author indeed is not a SW Engineer".

This is a pretty ridiculous notion if you just cursorily glance over the page. It is quite clear that this guy is more of a software engineer than most with that title will ever be. Hint: a blog that contains a post with a title like 'Coroutines in one page of C' is a software engineer.

Re:Why bad scientific code beats code following "best practi... by apelapan on Saturday January 06, 2024 @08:52AM (#38891414)
Long functions are not hard to grok, if they have a logical flow and stay reasonably close to a common level of abstraction (which can be high or low, doesn't matter). You just read top to bottom and follow the story.

20 files with 20 functions each does not cause high cognitive load, if the scope of each file and each function makes sense. You easily find the file+function you need, whenever you need to look something up and the rest of the time it is as if the rest didn't exist.

Good code can come in any shape. It is not shape itself that is important, it is the "goodness" that is important.

Re:Why bad scientific code beats code following "best practi... by whstl on Saturday January 06, 2024 @10:57AM (#38892448)
Yep. Long functions can be easier to read and simpler to follow than multiple methods, if they're well documented.

Carmack has a good essay about it.

http://number-none.com/blow/john_carmack_on_inlined_code.htm...

Re:Why bad scientific code beats code following "best practi... by __loam on Saturday January 06, 2024 @06:42PM (#38896783)
My heuristic is that if logic is repeated at least 3 times, it's good to pull out into its own function, and even then you still need to consider liskov substitution principle.
Re:Why bad scientific code beats code following "best practi... by strken on Saturday January 06, 2024 @04:39AM (#38889974)
There are some things that should be in one long function (or method).

Consider dealing with the output of a (lexical) tokeniser. It is much easier to maintain a massive switch statement (or a bunch of ifs/elseifs) to handle each token, with calls to other functions to do the actual processing, such that each case is just a token and a function call. Grouping them in some way not required by the code is an illusory "gain": it hides the complexity of the actual function in a bunch of files you don't look at, when this is not a natural abstraction of the problem at all and when those files introduce extra layers of flow control where tricky bugs can hide. Or see the "PLEASE DO NOT ATTEMPT TO SIMPLIFY THIS CODE" comment from the Kubernetes source[0]. A 300 line function that does one thing and which cannot be usefully divided into smaller units is more maintainable than any alternative. Attempting to break it up will make it worse.

That being said, I agree that nearly all 300 line functions in the wild are not like this.

[0] https://github.com/kubernetes/kubernetes/blob/ec2e767e593953...

Re:Why bad scientific code beats code following "best practi... by arthurcolle on Saturday January 06, 2024 @01:51AM (#38889106)
works until it doesn't
Re:Why bad scientific code beats code following "best practi... by stinos on Saturday January 06, 2024 @06:03AM (#38890389)
They

Who are these people, really? I mean, I was that for a rather brief period of like a year, somewhere 3-4 years into programming IIRC. I met others like it. But in the end people seem to learn and grow out of it, and rather quickly so, because it becomes clear what the issues are quickly. Really good learning by mistake though, wouldn't have wanted to miss out on it.

mantra

That's imo just another mistake to make: wrapping a rather strict and narrowly scoped principle in a paradigm-like-must-be-followed mantra hurts the right-tool-for-the-job idea, which feels vastly superior.

Firstly the idea that unmaintainable code is necessarily an issue is already wrong to start with, in my book. Obviously it's not ideal and where appropriate - meaning nearly always - should be avoided at pretty much all cost, but I have enough examples where it does not matter at all. As in: code which hasn't been touched in 20 years and probably won't ever be touched. Does it look like a nightmare? Yes. Does it work correctly? Yes. Does it need changing? No. So, is it an issue where spending time (or having spent time) on it would make anything other than the programmer's peace of mind (well, or ego perhaps) better? Clear no.

Secondly: of course I get where you're going with such definitions but it again lacks the very much needed nuancing. I can write unmaintainable code in one file but where you need to change 20 different locations. You could than claim that your mantra still applies because the code should have been split over 20 files, but yeah, that's what you get with mantras :) Likewise depending on the feature it's perfectly possible many files have to be changed but that doesn't necessariy mean the code is hard to maintain. Could try to claim that it wasn't very well architected to start with, maybe, but welcome in the real world where not everything can be thought of from the very start except in small toy applications.

Re:Why bad scientific code beats code following "best practi... by leksak on Saturday January 06, 2024 @10:19AM (#38892115)
Then a single file project is the most maintainable software project?
Re:Why bad scientific code beats code following "best practi... by naasking on Saturday January 06, 2024 @11:49AM (#38892917)
> How maintainable code is is measured in how many files you have to edit to add one feature.

Trivially false: if all of the source code is kept in one file then you only ever have to edit one file. No matter how many lines of code are in that file, any such system would be maximally maintainable by your definition.

Maintainability is not so clear-cut. It's currently an imprecise measure of organizational clarity that makes it straightforward to extend a system in ways that are needed or will be needed.

Re:Why bad scientific code beats code following "best practi... by patrulek on Saturday January 06, 2024 @12:22PM (#38893236)
I dont trust devs that praise clean code as much as i dont trust people that say they eat clean.