News for hackers. Stuff that matters.
Re:Rob Pike's 5 Rules of Programming by JanisErdmanis on Wednesday March 18, 2026 @07:51AM (#47424525)
With 100 functions and one datastructure it is almost as programming with a global variables where new instance is equivalent to a new process. Doesn’t seem like a good rule to follow.
Re:Rob Pike's 5 Rules of Programming by embedding-shape on Wednesday March 18, 2026 @08:42AM (#47425046)
The scope of where that data structure or functions are available is a different concern though, "100 functions + 1 data structure" doesn't require globals or private, it's a separate thing.
Re:Rob Pike's 5 Rules of Programming by JanisErdmanis on Wednesday March 18, 2026 @12:24PM (#47427750)
One can always look as global variables equivalent to a context object that’s is passed in every function. It’s just a syntactic difference whether one constructs such data structure or uses it implicitly via globals.

What I am getting at is that when one has such gigantic data structure there is no separation of concerns.

Re:Rob Pike's 5 Rules of Programming by CyberDildonics on Wednesday March 18, 2026 @01:34PM (#47428710)
Does one need one's separation of concerns if one's concerns shouldn't be separated in the in the first place?

Anytime one has access to a database one has access to one large global data structure that one can access from anywhere is a program.

This same concept goes for one's global state in one's game if one is making a game.

Re:Rob Pike's 5 Rules of Programming by JanisErdmanis on Wednesday March 18, 2026 @01:56PM (#47429018)
Separation of concerns is still a valid paradigm with a single global datastructure like GUI, Microservice, Database and etc. In such situation one can still seperate concerns via composing the global datastructure from a smaller units and define methods with respect to thoose smaller units. In that way one does not need to wonder whether there are some unattended side effects when calling a function that mutates the state.
Re:Rob Pike's 5 Rules of Programming by CyberDildonics on Wednesday March 18, 2026 @02:47PM (#47429775)
Seems like one is backpedaling because one was just talking about one's separation of one's concerns and now one is defending one's separation of concerns with respect to one's global data structure.
Re:Rob Pike's 5 Rules of Programming by JanisErdmanis on Wednesday March 18, 2026 @03:43PM (#47430489)
I still firmly believe that one ctx object and hundred functions/methods is as bad as programming with plain variables defined in the global scope. If the ctx is composed from smaller data structures with whom the functions are defined, then all is good. This is the opposite of the rule.
Re:Rob Pike's 5 Rules of Programming by CyberDildonics on Wednesday March 18, 2026 @05:16PM (#47431543)
But why?

You keep saying you believe it, but that is literally what a database is, game state manipulation, string manipulation, iterator algorithms, list comprehensions, range algorithms, image manipulations, etc. These are all instances where you use the same data structures over and over with as many algorithms and functions and you need.

Re:Rob Pike's 5 Rules of Programming by JanisErdmanis on Wednesday March 18, 2026 @08:41PM (#47433272)
It’s about coupling and being able to maintain that in the long term. A narrow focus helps to test each individual unit in isolation from each other. It is true that a database appears to be a single datastructure with hundreds of methods from the users perspective and that is fine, because someone else engineered and tested it for you. However if you were to look into how a database is implemented you would get to see the composition of data structures, like btrees that are tested in isolation.
Re:Rob Pike's 5 Rules of Programming by CyberDildonics on Wednesday March 18, 2026 @09:57PM (#47433863)
It’s about coupling and being able to maintain that in the long term.

What does that mean? This is all the kind of abstract programming advice that sounds nice until someone needs an example.

A narrow focus helps to test each individual unit in isolation from each other.

A function operating on a data structure is already a narrow focus.

It is true that a database appears to be a single datastructure with hundreds of methods from the users perspective

And also from a reality perspective because it's literally what a database is about.

However if you were to look into how a database is implemented you would get to see the composition of data structures, like btrees that are tested in isolation.

I don't know what point you're trying to make. Data structures should be tested? I don't think anyone is saying they shouldn't.

Re:Rob Pike's 5 Rules of Programming by JanisErdmanis on Thursday March 19, 2026 @06:21AM (#47437116)
To put it simply if you have a function f(ctx) = ctx.a + ctx.b it is hard to see what are the arguments producing the output. Which are the elements in the datastructure you need to vary in order to have exhaustive tests. Whereas if one refactors it as f(ctx) = g(ctx.a, ctx.b) you only need to test function g with respect to (a, b) whereas forwarding of methods can be simply covered in integration tests without any care whether function g is implemented correctly.

To make such testing strategy to work data structures need to be small. It is better to have multiple small data structures rather than one big universal one where methods are defined at the ctx level making exhaustive tests difficult.

Perhaps, I haven’t been clear. I agree with Pike’s advice strongly. What I am trying to say here is that the Perl’s rule 9 is diametrically opposite of what Pike says.

Re:Rob Pike's 5 Rules of Programming by CyberDildonics on Thursday March 19, 2026 @09:48AM (#47439398)
To make such testing strategy to work data structures need to be small.

Why would that be true?

It is better to have multiple small data structures rather than one big universal one where methods are defined at the ctx level making exhaustive tests difficult.

I don't think you are backing this up at all, you just keep saying it over and over. It's also not even about big data structures it's about having fewer data structures and using them over and over. You can see where this is effective even in javascript and lua with their tables that have hash maps and arrays.

Re:Rob Pike's 5 Rules of Programming by imtringued on Thursday March 19, 2026 @07:01AM (#47437406)
In languages without generics, like C, people tend to build a custom list type that only holds their particular type. This leads to a proliferation of list types each with sparse feature support.

It is better to have one collection type and use it everywhere directly.

Some Java developers had a tendency to encapsulate collections in <Type>Manager classes that grant limited operations/access to the list type. In practice this doesn't really buy you anything and you could have had a regular List<Type> instead.

Re:Rob Pike's 5 Rules of Programming by IIsi50MHz on Friday March 20, 2026 @02:44PM (#47458851)
"one data structure" doesn not have to mean "all data it one instance". Each of 100 functions could take a slice of data, or use a separate datastore which has the same structure. Separate instances of one structure can be passed by reference or value, and the receiver, because all 100 functions use the same data structure, understands what to do with what it received.