Most active commenters
  • stickfigure(3)

←back to thread

873 points belter | 30 comments | | HN request time: 0.518s | source | bottom
1. GuB-42 ◴[] No.42948407[source]
Just personal opinions, I guess, I agree with most, but here are some I disagree with:

- There is no pride in managing or understanding complexity

Complexity exists, you can't make it go away, managing it and understanding it is the only thing you can do. Simple systems only displace complexity.

- Java is a great language because it's boring

That is if you write Java the boring way. A lot of Java code (looking at you Spring) is everything but boring, and it is not fun either.

- Most programming should be done long before a single line of code is written

I went the opposite extreme. That is, if you are not writing code, you are not programming. If you are not writing code on your first day your are wasting time. It is a personal opinion, but the idea is that without doing something concrete, i.e. writing code, it is too easy to lose track of the reality, the reality being that in the end, you will have a program that runs on a machine. It doesn't mean you will have to keep that code.

- Formal modeling and analysis is an essential skill set

Maybe that explains our difference with regard to the last point. Given the opportunity, I prefer try stuff rather than formalize. It is not that formal modeling is useless, it is just less essential to me than experimentation. To quote Don Knuth out of context: "Beware of bugs in the above code; I have only proved it correct, not tried it." ;)

- You literally cannot add too many comments to test code (I challenge anyone to try)

time++; // increment time

replies(5): >>42948448 #>>42949655 #>>42949715 #>>42951149 #>>42963604 #
2. snapcaster ◴[] No.42948448[source]
I agree with you, i'm much more on the "try stuff out" scale vs. formal methods. That being said, i've worked with people who are the other way and still very effective. I think this one is more of a trade-off or personality thing than something that's "true" or "false"
replies(1): >>42949294 #
3. AnimalMuppet ◴[] No.42949294[source]
I agree with you that personality plays a role. But regardless of which way your personality pushes you:

You can never think enough up front to know all you need to know, or even 95%. You're not omniscient enough, and you never will be. Big Design Up Front fails because of this - you have to be able to iterate.

You also have to know what you're trying to build, and at least roughly how you're going to build it. If you don't, no amount of iteration and experimentation will enable you to converge on a solution. You need to experiment and iterate and explore within at least a sketch of a larger picture, not on a blank canvas.

replies(1): >>42950099 #
4. do_not_redeem ◴[] No.42949655[source]
> time++; // increment time

This isn't too many comments, it's a poor quality comment. Try:

time++; // advance 1 simulated second

replies(2): >>42949812 #>>42958980 #
5. coldpie ◴[] No.42949715[source]
> - There is no pride in managing or understanding complexity

> Complexity exists, you can't make it go away, managing it and understanding it is the only thing you can do. Simple systems only displace complexity.

I interpreted that one as a suggestion to avoid welcoming needless complexity because of the false sense of pride it gives you to successfully manage that complexity.

To give an example, I believe C++'s enduring popularity is mostly because of exactly this false sense of pride. You practically need a doctorate-level understanding of the language to use most of its features without stepping on the dozen landmines the language places in your way (I'm so smart because I: remembered to declare my destructors virtual and understand why; can interpret this 2MB of template errors in the compiler output; can """cleverly""" use operator overloads). It can feel nice to be a master of such a complex tool, but that's a false sense of pride. The complexity of your tooling is not the point; the end product is.

replies(3): >>42952203 #>>42952736 #>>42963369 #
6. bluGill ◴[] No.42949812[source]
What is wrong with

   time++;
That seem obvious enough to me without any comments.
replies(4): >>42950683 #>>42950807 #>>42956919 #>>42963696 #
7. snapcaster ◴[] No.42950099{3}[source]
True, the extreme version of any of these is usually wrong
8. smallerfish ◴[] No.42950683{3}[source]
Is it ms? seconds? days? weeks? months? How far up do I have to read to figure that out?

When I'm looking at a test case is broken, I ideally want context IN the actual test that lets me understand what the test author was thinking when they wrote it. Why does this test exist as it does? Why are the expectations that are in place valid? Write the comments for you-in-2-years.

replies(4): >>42951256 #>>42951334 #>>42952723 #>>42960176 #
9. m-zuber ◴[] No.42950807{3}[source]
That code (in isolation) does not tell me what unit time is though
10. mbonnet ◴[] No.42951149[source]
I think the "most programming" thing has to be determined according to project type. You should have your architecture and data relationships all figured out long before coding when it comes to safety-critical systems.
11. bluGill ◴[] No.42951256{4}[source]
Do you not know the conventions of your project? Doesn't your project have a convention that all time is in ms (second, weeks...)?

If your project doesn't have that convention such that everyone knows than the code should be

timeMs++;

You may also have a time type and so you can use your IDE to examine the type.

replies(2): >>42956357 #>>42956741 #
12. danjl ◴[] No.42951334{4}[source]
I would prefer `somethingSec`, where "something" indicates the usage better than "time". E.g. `delaySec` or `elapsedSec`.
replies(1): >>42960504 #
13. GuB-42 ◴[] No.42952203[source]
C++ complexity exists for a reason. It does a lot of things and these things are useful, if not necessary for those who use it. I can't think of any language that can replace C++ completely. Plenty can replace C++ incompletely, but then you would need another language for the leftovers, that's displacing complexity.

There are modern languages trying to eat C++ lunch, like Zig and Rust, but you don't get decades of backward compatibility, and they are not particularly simple either. Rust in particular is one of the most complex programming language in use today, it could definitely be simplified by removing the borrow checker and lifetime things and make "unsafe" implicit, leave memory safety to the programmer. But it makes no sense because Rust was designed for memory safety and performance, which is a complex problem, and therefore Rust is complex.

replies(2): >>42956718 #>>42960926 #
14. vunderba ◴[] No.42952723{4}[source]
Pedantic but a comment clarifying the unit of measurement belongs with the declaration of the variable, not an increment statement.
replies(1): >>42962621 #
15. compiler-guy ◴[] No.42952736[source]
C++'s enduring popularity is mostly inertia from the time it was if not the only game in town, the biggest, baddest game in town, and from being the souped-up (if overly complex) successor to the previous biggest, baddest game in town.

Thousands of companies collectively have billions of lines of code in C++. Millions of programmers know it well enough to get the job done. Entire ecosystems with absolutely huge areas are well defined by C++ (and previously C).

Rewriting all this code would be a gargantuan task. It all mostly works (yes, it has bugs, lots of them, but it is still mostly doing the job). The "R" in "ROI" for rewriting it is extremely low and hard to predict, and the "I" is very high.

And that is why old programming languages live on. Not because people take pride in being geniuses or the ability to code in it, but because inertia is really hard to change.

16. rovolo ◴[] No.42956357{5}[source]
I agree that the time unit should be in the variable name. The code itself should do a good job of explaining "what" is happening, but you generally need comments to explain "why" this code exists. Why is the test advancing the time, and why are we advancing the time at this line of the test?

    networkTimeMs++; // Callback occurs after timeout

    timeSec++; // Advance time to check whether dependent properties update

    utcTime++; // Leap second, DON'T advance ntpTime
replies(1): >>42956777 #
17. stickfigure ◴[] No.42956718{3}[source]
> C++ complexity exists for a reason.

Yeah, because Bjarne was figuring it out as he went. Which is fair, he was treading new ground. But C++ would have turned out a lot better if he'd taken a lot more vacation time.

18. stickfigure ◴[] No.42956741{5}[source]
> Do you not know the conventions of your project?

I just started yesterday! No, I don't.

19. stickfigure ◴[] No.42956777{6}[source]
> I agree that the time unit should be in the variable name

Also a terrible solution!

The code suffers from primitive obsession. Unless you're in a code section that is known to have performance issues, use real types.

    time = time.plusMilliseconds(1);
replies(1): >>42962556 #
20. johnnyanmac ◴[] No.42956919{3}[source]
It will vary immensely on how readable the actual code base it, but what comes to mind:

1. what units? I was just caught in this with a function with a timeout. I had to look at the docs to find out this was actually in nanoseconds (stuff like this is why I came more around to verbose parameter names).

2. what's the function of the timer?

3. (potential code smell) Do I need to manually increment such a timer for the test? is the time library a necessary part of the test (or perhaps what we testing)?

21. steve_adams_86 ◴[] No.42958980[source]
Like many comments, I find we can eliminate it without losing anything by using better variable names.

   seconds++;
That gets the idea across very clearly to me and has the benefit of (likely) making the rest of the code clearer too
replies(1): >>42966525 #
22. kelnos ◴[] No.42960176{4}[source]
That just means the variable isn't named correctly, not that it needs a comment. Just name it 'time_seconds" or whatever and save yourself the extraneous typing.

I tend to be a minimalist when writing comments. If I have to write out a comment to describe what I'm doing (like "advance 1 simulated second"), then I have failed at writing clear code. Sometimes I will write a comment to explain why I am doing something, if it's not clear (like "manually advance time to work around frobbing bug in foobar").

Comments add to your maintenance burden. Writing clearer code can often reduce that burden.

23. creamyhorror ◴[] No.42960504{5}[source]
Same here - unit-specifying variable names like "delaySecs" and "amountBaseCcy" (where any possibility of ambiguity exists) are exactly what I enforce on our projects (when types aren't providing the guarantee). It makes avoiding and detecting mistakes easier, because you can immediately see where logic has gone wrong.
24. DeepSeaTortoise ◴[] No.42960926{3}[source]
IMO Rust is hard until you gain some intuition, then it becomes MUCH easier.

The real frustrating part is claiming to embrace errors by returns, but then still just panicing all over the place, dependencies piled upon dependencies piled upon dependencies, just about 0 documentation on doing anything asynchronous without external dependencies, important features being kept in unstable for basically ever, one of the highest barriers to contribute to language features, highly questionable leadership processes and the worst of all:

Openly embracing design complexity. When I learned about extension traits for the first time, I thought "That's awesome", only to find not much later crates, that seem to have some features, which I couldn't find the implementation for anywhere. Turns out external crates were pulled in, which then were used to extend anything carrying certain marker-traits from the previous crate. Like WHY?

25. tialaramex ◴[] No.42962556{7}[source]
In a performance language your "real types" aren't somehow more expensive and so you should only use the built-in primitives when they accurately reflect your intent. So I would write:

time += Duration::from_millis(1);

But I would expect that "time unit should be in the variable name" is a reasonable choice in a language which doesn't have this affordance, and I needn't care about performance because apparently the language doesn't either.

I also wonder why we've named this variable "time". Maybe we're a very abstract piece of software and so we know nothing more specific? I would prefer to name it e.g. "timeout" or "flight" or "exam_finishes" if we know why we care about this.

26. tialaramex ◴[] No.42962621{5}[source]
The problem, in this case, is that the correct size of the increment involves the unit of measurement. If we change the unit of measurement and go update your comment on the declaration of the variable, now everywhere which uses the variable is wrong.

    int time; // in seconds
    /* thousands of lines away or in another file */
    time += 1;
Later we change the time to be in milliseconds. We update the comment on the declaration, but now that code is wrong and we have no reason to know that.

That's a bad choice, languages should do better (and some do - where they do, use the better features and this problem vanishes) but when it's forced upon us it makes sense to either put the unit in the name of the variable or ensure comments about changes to the variable explain the units consistently, even though that's lots of work. This extra work was dumped on you by the language.

27. xedrac ◴[] No.42963369[source]
Yes, C++ developers seem particularly prone to adding unnecessary complexity. I'm not sure why that is, but they feel compelled to only program the most generic, ultra flexible solutions, even though it'll likely only every get used in fairly simple ways. But you forever have to pay the cost of that complexity for virtually zero benefit.
28. gtirloni ◴[] No.42963604[source]
> Complexity exists, you can't make it go away, managing it and understanding it is the only thing you can do. Simple systems only displace complexity.

My thoughts, exactly. And considering that so much unnecessary complexity keeps being added to software (through poor understanding of requirements, technical debt, etc), it's an extremely valuable skill.

29. Daishiman ◴[] No.42963696{3}[source]
Advance a frame, a second, or a millisecond?
30. sethammons ◴[] No.42966525{3}[source]
and the variable will invariably store milliseconds because someone didn't read the docs on timelib.Now() or store an int as a counter for makeshift vector clock :p

types for the win