Rule 6: Every well-intentioned rule will be bastardized and used to justify horrible code. Foo: "Hey, this 10000-element collection, which we do repeated lookups on... why are we using a list and not a HashSet?" Bar: "Because lists are so much simpler than a HashSet. Let's just KISS" Foo: "But... doing repeated lookups on a 10k sized list is so much slower than just using a HashSet!" Bar: "Oh really? Have you profile…
Rob Pike’s Rules of Programming (1989)
51–60 of 122 posts
Re: Rob Pike’s Rules of Programming (1989)
#52The sum of these rules seem to imply that it's difficult to theoretically model programming, so always wait for your program to be fully written so you can perform some brute force empiricism -- and only then think about performance.
Like his creation, the Go language, Rob Pike's rules are somewhat condescending and patronizing those he deems as lesser programmers.
Rule 3, however, is the exception. That is the take away gem based on experience.
Re: Rob Pike’s Rules of Programming (1989)
#53Rule 6: Every well-intentioned rule will be bastardized and used to justify horrible code. Foo: "Hey, this 10000-element collection, which we do repeated lookups on... why are we using a list and not a HashSet?" Bar: "Because lists are so much simpler than a HashSet. Let's just KISS" Foo: "But... doing repeated lookups on a 10k sized list is so much slower than just using a HashSet!" Bar: "Oh really? Have you profile…
How is writing code that loops over a list simpler than calling: things.Get("key") ?
In terms of program speed/optimization, the answer depends on how .Get() is implemented.
Re: Rob Pike’s Rules of Programming (1989)
#54Earlier quoted context omitted.
A set , the abstract interface, is simpler conceptually than a list. A hash set, the particular implementation of a set, is more complex.
One could easily implement a hash set with an array, the reverse is not true at all. From the outside, arrays are extremely flexible, powerful, and complex constructs; a set, even a hash set, is not. If it is easy to procure a set (as a hash set), then sets should be used when they could be used instead of arrays (unless there are performance concerns to using sets). In languages that do not include batteries (e.g. C…
Lots of low-level data structures can be implemented in terms of one another, and which makes sense depends on circumstance.
Re: Rob Pike’s Rules of Programming (1989)
#55Rule 6: Every well-intentioned rule will be bastardized and used to justify horrible code. Foo: "Hey, this 10000-element collection, which we do repeated lookups on... why are we using a list and not a HashSet?" Bar: "Because lists are so much simpler than a HashSet. Let's just KISS" Foo: "But... doing repeated lookups on a 10k sized list is so much slower than just using a HashSet!" Bar: "Oh really? Have you profile…
If they don't need order, a hash set is indeed more simple conceptually.
Re: Rob Pike’s Rules of Programming (1989)
#56Earlier quoted context omitted.
How is writing code that loops over a list simpler than calling: things.Get("key") ?
The interface is the same. For example, in C# you have an interface Collection, which offers a lookup method, and which both HashSet and Lists implement. The point of the OP is that among different implementations for the same interface, choose the simplest one unless you have empirical evidence that compels you to do otherwise.
Re: Rob Pike’s Rules of Programming (1989)
#57Re: Rob Pike’s Rules of Programming (1989)
#58These are not "Rules of Programming", but are excellent "Guidelines for Performance". Having 30yrs under my belt I have come to all the same conclusions as Rob Pike over my years, so these are very deserving of some serious contemplation for those with In my current job we have lots of large and often 'sparsely populated' objects which means basically you can never count on any of the properties you were hoping would…
(He also designed his latest language without inheritance)
Re: Rob Pike’s Rules of Programming (1989)
#59Earlier quoted context omitted.
I've found that even as a user it is very useful to have a mental image of what the "data model" looks like, abstractly. This is more important than knowing about all the features of an application. I'm thinking user documentation should start with a quick explanation of the data model, and from there describe the operations that can be performed on it.
Yeah, the data structures define the program. Both downwards towards the developer and upwards towards the user.
“Although some jokingly called Blender a ‘struct visualizer’, the name is actually quite accurate. During the first months of Blender's development, we did little but devise structures and write include files. During the years that followed, mostly tools and visualization methods were worked out.”
And the architecture of a compiler I’ve been working on has gotten considerably simpler and more solid as I’ve figured out the right data structures—with the right data model, especially if it’s enforced with types, the code practically writes itself. Finding that model is the hard part.
Re: Rob Pike’s Rules of Programming (1989)
#60Earlier quoted context omitted.
How is writing code that loops over a list simpler than calling: things.Get("key") ?
The interface is the same. For example, in C# you have an interface Collection, which offers a lookup method, and which both HashSet and Lists implement. The point of the OP is that among different implementations for the same interface, choose the simplest one unless you have empirical evidence that compels you to do otherwise.
How does a List map values to key? How does it even represent them?