News for hackers. Stuff that matters.
Re:What I learned working with a senior engineer as a new grad by dchapp on Friday August 19, 2022 @09:48AM (#32520896)
> Long verbose names don't cost anything

They absolutely do have a cost. The question is whether the benefit they bring in implicit documentation is worth their cost.

> Even beyond the DX of readable names, it also acts like a type-checker. By reading the code, you can verify at least the semantics make sense.

I would strongly prefer that the actual type system do this job instead. As a toy example, if a function is only meant to operate on "lengths" (i.e., non-negative scalar values) then that should be modeled in the types of its arguments, not in its name.

Re:What I learned working with a senior engineer as a new grad by edflsafoiewq on Friday August 19, 2022 @12:29PM (#32523080)
Modelling in the type system has a cost too. You have to digest a lot of text (wrapping & unwrapping, etc.) just to understand that you're passing a length. Comparatively some extra characters in an identifier are basically free and can tossed in anywhere.
Re:What I learned working with a senior engineer as a new grad by dchapp on Friday August 19, 2022 @01:46PM (#32524040)
That may be a fair criticism in some cases.

For my toy example I don't think it is because it's generally easy (in the languages I work in) to overload arithmetic operators on types that are basically constrained scalars so there's no explicit wrapping/unwrapping to do when you want to operate on them as if they were plain scalars.

Maybe you could give me an example of the kind of pathological situation you're alluding to?

Re:What I learned working with a senior engineer as a new grad by shepherdjerred on Friday August 19, 2022 @10:13AM (#32521196)
> I would strongly prefer that the actual type system do this job instead. As a toy example, if a function is only meant to operate on "lengths" (i.e., non-negative scalar values) then that should be modeled in the types of its arguments, not in its name.

Have you never worked in a dynamically typed language?

Re:What I learned working with a senior engineer as a new grad by dchapp on Friday August 19, 2022 @11:09AM (#32521959)
I have. I prefer statically typed languages.
Re:What I learned working with a senior engineer as a new grad by plonk on Friday August 19, 2022 @01:57PM (#32524170)
Python is only palatable with strict type checking everywhere. I don't see how unchecked dynamic typing can bring anything else than chaos in a large project.
Re:What I learned working with a senior engineer as a new grad by __Parfait__ on Friday August 19, 2022 @09:51AM (#32520920)
What's the cost?
Re:What I learned working with a senior engineer as a new grad by dchapp on Friday August 19, 2022 @11:11AM (#32521977)
Readability. In particular, an increase in the rate at which long, verbose names which are mostly the same are confused with one another.
Re:What I learned working with a senior engineer as a new grad by nnnnico on Friday August 19, 2022 @10:27AM (#32521385)
>They absolutely do have a cost.

what cost? aesthetics?

Re:What I learned working with a senior engineer as a new grad by patrick451 on Friday August 19, 2022 @11:10AM (#32521973)
Long, verbose variables are hard too read (it literally takes more time to read more characters), cause excessive line breaks, are harder to remember, and in general hurt readability more than they help.
Re:What I learned working with a senior engineer as a new grad by purplerabbit on Friday August 19, 2022 @10:42AM (#32521597)
Cognitive overload. Storing 3-4 succinct variable names in your head takes the same energy as storing 1-2 verbose variable names in your head.
Re:What I learned working with a senior engineer as a new grad by Jcampuzano2 on Friday August 19, 2022 @10:59AM (#32521833)
I think there's some nuance though. If I'm the one writing the code, sure I can keep 3-4+ succint names of things I came up with in my head.

But then somebody else needs to look at this code in the future, and they're scratching their head as to what these names represent. Or somebody didn't really put enough thought into what the variables are, or gave them a name that only half represents what they actually mean.

I basically threw away all care for how long a variable name is long ago and have never had a problem. I just name it with enough words it needs to describe what it represents and don't fuss with making it smaller. With a decent IDE you don't even have to remember the whole name for things half the time, only parts of it.

Re:What I learned working with a senior engineer as a new grad by __Parfait__ on Friday August 19, 2022 @10:58AM (#32521821)
Cognitive overload.. Perhaps it'd be best to provide and example of a "verbose" variable name as compared to a "succinct"

Personally I'm thinking more along the lines of

Succinct ->KEY

Verbose -> MAIL_SERVICE_API_KEY