News for hackers. Stuff that matters.
Re:You Want Modules, Not Microservices by SomeoneOnTheWeb on Tuesday January 03, 2023 @08:04AM (#34230840)
I strongly disagree on this one. 10+K lines files are absolutely unreadable most of the time. Separating business logic than other parts of the application helps maintaining it and making everything evolve in parallel, without mixing things up. It also helps to clearly see where business logic happens.
Re:You Want Modules, Not Microservices by karamanolev on Tuesday January 03, 2023 @08:08AM (#34230868)
I'm inbetween. 10K line files are usually extremely messy, but they can be written not to - a large number of well-organized, well-capsulated <100 LOC classes can be very readable if smashed together in one file. It just so happens that people who tend to write readable self-contained classes just don't put them in 10 KLOC files, but rather split them. And vice-versa, creating an association "10 KLOC files are unreadable", where it's not the length of the file, but rather the organization itself.

Same for business logic - very clear separation can be cumbersome sometimes, but otherwise it becomes messy if you're not careful. And careful people just tend to separate it.

Re:You Want Modules, Not Microservices by sbergot on Tuesday January 03, 2023 @08:13AM (#34230905)
I disagree with this stance. Creating a file and naming it gives it a purpose. It creates a unit of change that tools like git can report on.
Re:You Want Modules, Not Microservices by nonethewiser on Tuesday January 03, 2023 @08:33AM (#34231064)
A line is a unit of change that git can report on.

If it's a separate file that is scoped to some specific concern, sure. But its tgat grouping by concern that is key. Not separation into another file. Extracting ra dom bits of code into separate files would be _worse_.

Re:You Want Modules, Not Microservices by swsieber on Tuesday January 03, 2023 @11:03AM (#34233165)
> A line is a unit of change that git can report on.

Yes and no.

Git doesn't store lines, it stores files. Git diff knows how to spit out line changes by comparing files.

So to run git blame on a 10k line file you're reading multiple versions of that 10k file and comparing. It's slow. Worse still is that trying to split said file up while trying to preserve history won't make the git blame any faster.

Re:You Want Modules, Not Microservices by karamanolev on Tuesday January 03, 2023 @12:33PM (#34234693)
Yes and yes. While agree with the general points, note that they didn't say "unit that git stores", but "unit git can report on". Git can totally report on lines as a unit of change.
Re:You Want Modules, Not Microservices by beagle3 on Tuesday January 03, 2023 @08:27AM (#34231017)
got diff understands function boundaries, and for many languages will “report” equally well on a single file.

It’s a good idea to break things down to files along logical boundaries. But got reporting isn’t a reason.

Re:You Want Modules, Not Microservices by joshuamorton on Tuesday January 03, 2023 @04:41PM (#34238490)
Git diff absolutely does not understand function boundaries, it's diff algorithms routinely confuse things like adding a single new function, thinking that the diff should begin with a "}", instead of a function definition.
Re:You Want Modules, Not Microservices by regularfry on Tuesday January 03, 2023 @09:05AM (#34231417)
What muddies the waters here is languages like Java, where "10k lines" means "you've got a 10kLOC class there", and ecosystems like PHP's where while there's nothing in the language to require it, people and teams will insist on one class per file because hard rules are easier to understand and enforce than "let's let this area evolve as we increase our understanding".

As long as what's there is comprehensible, being able to evolve it over time is a very useful lever.

Re:You Want Modules, Not Microservices by marcosdumay on Tuesday January 03, 2023 @10:06AM (#34232268)
It varies a bit with language and tooling, but 10k lines is around the place where the size of your file by itself becomes a major impediment on finding anything and understanding what is important.

A 10k lines file is not something that will completely destroy your productivity, but it will have an impact and you'd better look out for it growing further, because completely destroying your productivity is not too far away. It is almost always good to organize your code when it reaches a size like this, and the exceptions are on contexts where you can't, never on contexts where it's worthless.

Re:You Want Modules, Not Microservices by karamanolev on Tuesday January 03, 2023 @12:18PM (#34234390)
I generally agree. My argument is that 10K lines written one way can certainly be more readable than 10 files x 1K lines written in a different way, so the real differentiator is the encapsulation and code style, not KLOC/file per se.
Re:You Want Modules, Not Microservices by pshirshov on Tuesday January 03, 2023 @08:06AM (#34230859)
And of course it's lot easier to read 200k+ LoC shattered around twenty repos.
Re:You Want Modules, Not Microservices by koliber on Tuesday January 03, 2023 @08:10AM (#34230885)
The problem arises when you need to read the code of other modules or services. If you can rely on them working as they should, and interact with them using their well-defined and correctly-behaving interfaces, you won't need to read the code.

I'm a proponent of keeping things in a monolith as long as possible. Break code into files. Organize files into modules. A time may come when you need to separate out services. Often, people break things out too early, and don't spend enough effort on thinking how to break things up or on the interfaces.

Re:You Want Modules, Not Microservices by pshirshov on Tuesday January 03, 2023 @08:20AM (#34230961)
> and interact with them using their well-defined and correctly-behaving interfaces, you won't need to read the code.

Don't you want determinism and deterministic simultations? If you do, you'll also need stub implementations (mocks, dummies) for your interfaces.

Some notes on that: https://blog.7mind.io/constructive-test-taxonomy.html

> A time may come when you need to separate out services.

Most likely it won't if you organise properly. For example, if each your component is an OSGi module.

Re:You Want Modules, Not Microservices by rightbyte on Wednesday January 04, 2023 @04:34AM (#34243731)
> The problem arises when you need to read the code of other modules or services. If you can rely on them working as they should, and interact with them using their well-defined and correctly-behaving interfaces, you won't need to read the code.

You can say the exact same thing about C-headers though.

Re:You Want Modules, Not Microservices by SomeoneOnTheWeb on Tuesday January 03, 2023 @08:45AM (#34231195)
No, to me that's equally as bad. But 100k lines split across 500 well-named files is a lot easier to work with than 10+K line files or multi-repo code.
Re:You Want Modules, Not Microservices by naasking on Tuesday January 03, 2023 @09:27AM (#34231704)
With an IDE you're can just look at the class hierarchy/data types rather than the files. As long as those are well organized, who cares hoe they span files?

For instance, in C# a class can span multiple files using "partial" or you can have multiple classes in a single file. It's generally not an issue as long as the code itself is organized. The only downside is the reliance on an IDE, which is pretty standard these days anyway.

Re:You Want Modules, Not Microservices by surprisetalk on Tuesday January 03, 2023 @08:11AM (#34230887)
Honest question: do you think the same exact 10+K lines of code are easier to read spread across 1,000 files? And why do you think the overhead of maintaining the extra code for module boundaries is worth it?

EDIT: And what editor do you use? I'm wondering if a lot of these differences come down to IDEs haha

Re:You Want Modules, Not Microservices by nonethewiser on Tuesday January 03, 2023 @08:36AM (#34231097)
> Honest question: do you think the same exact 10+K lines of code are easier to read spread across 1,000 files?

This is a fair point but assumes 1 particular use case. It is easier if you are just concerned with a bit of it. If you need to deal with all of it, yeah, good fucking luck. 10k LOC file or 1k 100 LOC files.

Re:You Want Modules, Not Microservices by SomeoneOnTheWeb on Tuesday January 03, 2023 @08:44AM (#34231182)
10+K lines spread across 1k file is equally as bad as 10+K line files IMO.

I tend to ensure each file serves exactly one purpose (e.g. in C# one file = one class, with a only few exceptions).

I use VS Code, but in every IDE with a file opening palette it's actually really fast: you want to look for the code to, let's say, generate an invoice, just search for "invoice" in the list of files and you'll find it immediatly.

(Also modules have their own problem, I was mainly talking in a general way since that's what the parent comment was talking about.)

Re:You Want Modules, Not Microservices by osigurdson on Tuesday January 03, 2023 @08:50AM (#34231248)
The right answer is 20 files with 500 lines in each - i.e. few pages of clean/ readable/logical/well-factored code. Obviously it depends on the code itself - it's is fine to have longer files if highly correlated. Stateful classes should be kept short however as the cognitive load is very high.

I also find that updating code to take advantage of new/better language features / coding styles, etc. is impossible to do on a large code base at once. However, sprinkling these kind of things randomly leads to too much inconsistency. A reasonable sweet spot is to make each file self-consistent in this regard.

My experience stems from larger 500+ person-year projects with millions of lines of code.

Re:You Want Modules, Not Microservices by hbrn on Tuesday January 03, 2023 @11:05AM (#34233204)
The right answer is that there is no right answer. You shouldn't divide your code based on arbitrary metric like size, you should divide it based on concepts/domains.

If a particular domain gets big enough it probably means it contains sub-domains and can benefit from being divided too. But you cannot make that decision based on size alone.

Re:You Want Modules, Not Microservices by osigurdson on Tuesday January 03, 2023 @02:32PM (#34236736)
Sure but no problem domain is not going to lead you to 10,000 single line files. Similarly it will likely lead to very few 10K line files. There will likely be a way to factor things into reasonable sized chunks. File sizes are not going to be that highly coupled to problem domain as there are multiple ways to solve the same problem.
Re:You Want Modules, Not Microservices by hbrn on Tuesday January 03, 2023 @03:06PM (#34237239)
Sure, but it can lead to 1000 lines which some people still think is too much.

The point is that a numeric upper bound on LoC is inherently subjective and pointless. Instead of measuring the right thing (concepts) you're measuring what's easy to measure (lines).

In fact, it usually makes things worse. I've seen it over and over: you have N tightly coupled classes in a single file which exceeds your LoC preference.

Instead of breaking the coupling you just move those classes into separate files. Boom, problem solved. Previously you had a mess, now you have a neat mess. Great success!

Re:You Want Modules, Not Microservices by bombolo on Wednesday January 04, 2023 @02:20AM (#34242987)
> EDIT: And what editor do you use? I'm wondering if a lot of these differences come down to IDEs haha

Yes java developers can't do anything without their IDE. It helps them mask the 30000 nested directories they've created to "organize" the code.