Re:It's probably time to stop recommending Clean Code (2020)
by MillenialMan on Wednesday May 26, 2021 @04:27AM
(#27287828)
I posted this elsewhere in the thread, but local blocks that define which variables they read, mutate and export would IMO be a very good solution to this problem:
There are a couple of newer languages experimenting with concepts like this, Jai being one: https://youtu.be/5Nc68IdNKdg?t=3493
[ Parent
| on HN ]
Re:It's probably time to stop recommending Clean Code (2020)
by throwaway2037 on Thursday May 27, 2021 @10:27AM
(#27303556)
This is a fascinating idea. In some languages like C or Java or C#, the IDE can probably do this "for free" -- generate, then programmer can spot check for surprises. Or the reverse, highlight a block of code and ask the IDE to tell you about read/mutate/export. In some sense, when you use automatic refactoring tools (like IntelliJ), extract a few lines of code as a new method needs to perform similar static analysis.
In the latest IntelliJ, the IDE will visually hint about mutable, primitive-typed local variables (including method parameters). A good example is a for loop variable (i/j/k). The IDE makes it stand-out. When I write Java, I try to use final everywhere for primitive-typed local variables. (I borrowed this idea from functional programming styles.) The IDE gives me a hint if I accidentally forget to mark something as final.
Re:It's probably time to stop recommending Clean Code (2020)
by ajuc on Thursday May 27, 2021 @11:31AM
(#27304283)
> local blocks that define which variables they read, mutate and export would IMO be a very good solution to this problem:
this is basically a lambda you call instantly.
[&x, y, z] () {
x = y + z;
}();
Re:It's probably time to stop recommending Clean Code (2020)
by MillenialMan on Friday May 28, 2021 @05:33AM
(#27313333)
It's similar, but lambdas don't specify the behaviour as precisely, and they're not as readable since the use of a lambda implies a different intention, and the syntax that transforms them into a scope block is very subtle. They may also have performance overhead depending on the environment, which is (arguably) additional information the programmer has to consider on usage.