News for hackers. Stuff that matters.
Re:Please put units in names by yummybear on Monday March 21, 2022 @03:04AM (#30751080)
I can understand the reasoning, in this specific case. But having every function designating their unit is a new hungarian notation. Imagine working with:

setSpeedInKilometersPerSecond vs. setSpeed

I'd rather have it baked into the language ala CSS ("100ms").

Re:Please put units in names by berkes on Monday March 21, 2022 @04:55AM (#30751807)
First, I'd say that you probably want to invest in your IDE or editor.

But more important: there's middleground. What about setSpeedMmps() if setSpeedInMillimeterPerSecond is too noisy.

My ROT is that the unit or type designation schould not overshout the most important info. Which, in case of setSpeedInMillimeterPerSecond is arguably, indeed the case. But the solution is almost never binary, but a more succint version. Everyone understands km, mm, sec, hr (though the win with such is silly) px and so on.

Re:Please put units in names by ParetoOptimal on Tuesday March 22, 2022 @09:43PM (#30773894)
> What about setSpeedMmps

Mmps would be confusing and frustrating the first time I think.

Re:Please put units in names by kuu on Monday March 21, 2022 @03:21AM (#30751203)
Do they charge you by written bytes? I really don't see the problem with larger function names...
Re:Please put units in names by OskarS on Monday March 21, 2022 @03:58AM (#30751459)
"It's annoying" is a pretty good reason. If you don't mind function names like that, go become a Java Enterprise programmer, see how you like it after a few years.

In addition: it's the wrong solution to the problem. The units shouldn't be baked in to the function definition, just the type of quantity. You should be able to do both:

    setSpeed(10 m/s)
and

    setSpeed(45 km/h)
Which you can do in many languages. In fact, time functions in C++ work exactly like this. If you want to suspend a thread for 10 seconds you do

    std::this_thread::sleep_for(10s);
but if you want to suspend it for 5 milliseconds, you do

    std::this_thread::sleep_for(5ms);
And if you just supply a unitless number, it's a compiler error.
Re:Please put units in names by Mazzen on Monday March 21, 2022 @06:43AM (#30752445)
You are missing one crucial element here: `setSpeed(meterPerSecond: float)`
Re:Please put units in names by tirpen on Monday March 21, 2022 @03:59AM (#30751468)
Are you coding without any form of auto completion?
Re:Please put units in names by qayxc on Monday March 21, 2022 @06:04AM (#30752230)
As silly as this may sound, you may run into issues with certain linters or formatting tools in some languages.

A prominent example is PEP8 in Python, which suggests a line length limit of 79 characters (though 80-100 chars are considered to be "OK" as well). Long variable or function names can lead to distracting "forced" line breaks in such scenarios.

Re:Please put units in names by yummybear on Tuesday March 22, 2022 @12:19PM (#30767991)
Is anyone these days? That said I, personally, do prefer more concise naming.
Re:Please put units in names by ParetoOptimal on Tuesday March 22, 2022 @09:44PM (#30773900)
IMO it's about readability, not the typing that can be automated.