So #SoftwareDevelopment is trending in my timeline, and it's full of crap advice.

Here is an example, the problem with meaningless names, telling programmers to make more descriptive variables. This is absurdly stupid advice.
The actual problem is "empathy", seeing code from the point of view of a stranger, or even yourself a year later when you need to reread the code. You have to put yourself in their shoes, to see your code from their point of view.
A variable's purpose should be derived from its name, not the other way around.

For example, you extract a row from a database containing a person's details. Don't call it "row", call it "person" as the variable name.
Yes, yes, it's a row in the database, so you've derived the name from what's going on. But going the reverse direction, going from "row" to what the variable is supposed to do, is difficult for the person reading the code.
That's the problem with most variables: they are meaningful to the original programmer, but much less meaningful to the person reading the code.
So the prescription isn't "make variable names more descriptive" but "put yourself in the shoes of the reader". Yes, it's a row in the database, but is this the most helpful way to describe the variable?
I say "empathy" here going back to the original meaning of the word (putting yourself in somebody else's shoes), not the modern weepy definition (sympathy for a person). That other person may be future you, so at least put yourself in the shoes of future you.
I forgot, I was also going in this direction: overly long (overly descriptive) variable names are also a pox on programming.
Programming is a choice between variables names that are long enough but not too long. That's why they are compressed, like "pkt" instead of "packet", or "buf" instead of "buffer".
Basic concepts should have basic names. For example, "i" is a GREAT index variable for loops. A "buf" is a great name for a buffer. That's because these concepts are so ingrained to programmers that you only need a hint rather than a full explanation.
But conversely, don't use 'i' for things other than indexes. I saw some code recently that chose "buf" for something that was technically a buffer, so unlike the norm is took me extra time to figure out what was really going on.
Oh, and back to empathy: when choosing a name, maybe instead of "descriptive" choose something "can't be confused with anything else".

I ended up renaming their "buf" to something that wasn't very descriptive, but which couldn't be confused with normal buffers.
Choosing names is ultimately an art rather than a science, but big development organizations (falsely) try to make it a science. They often have rules on how to name things:
The biggest evil is Microsoft's "Hungarian" notation, prefixing variables with their type, such as dwColor, a variable that would store "color" information as a "double word" (meaning, 32-bit integer).
This was actually helpful around 1990 when code in C/C++ was constrained by the limited memory, CPU speed, and inflexibility of interfaces.

In today's world, it's a stupid anachronism that should be gotten rid of.
In today's world, a "Color" is an abstract type holding color information whose representation in memory is undefined, whether 32-bit integr or floating point or whatever.
Hey Microsoft, Hungarian notation is an anachronism, the rest of the world is laughing at you.
Big development organizations have big rules, such as style guides on how their programmers should program.
This is not a science that makes things go better, but an artifact of politics. Big orgs are full of people wanting to tell other people what to do.
Politics are toxic. There are programmers who just want to program. Then there are programmers who want to tell others how to do things. You can recognize them when you go to their office, what sorts of books they have on their shelf.
Some will have books like the essentials of cryptography, that teach technical subjects. Others have shelves full of "process" books, like about "Agile", as they try to convince the organization to adopt whatever they think is good process, style, rules, etc.
I was kinda like that as a kid, very much a nerd who cared about the finer details of things.
But when I was finally put in charge of engineering, able to enforce what I thought was the best "style", I had matured to the point of no longer caring.
The correct style is ultimately simply "things that other programmers won't find surprising" or "just like all the open-source you see on the Internet". Also, code in THEIR style unless you take ownership, in which case then convert to your style.
As you edit somebody else's code, then choose naming conventions that are the same as them. If they use "buf" for buffers, then you should do when adding more functions that manipulate buffers, for example.
On the other hand, when I've adopted code, after running a tool like clang-format to reformat the code, I'll go through and rename variables. It's a good time to do so, because I'm currently an outsider, and am at the peak empathy of how outsiders view the names.
The lesson of the last tweet isn't that I think I'm a better programmer than those jerks who chose confusing names originally, but that I'm in a better position, able to appreciate the code as an outsider in ways the original programmers couldn't.
When we read code, we wonder about the idiots who wrote it. In reality, it was written long ago for one purpose/context and has changed over time passing through multiple hands. What looks like spaghetti crap now could have started life as beautiful elegance.

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Robᵉʳᵗ Graham

Robᵉʳᵗ Graham Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @ErrataRob

Apr 21
What bothers me about this is the abject failure of basic civics. Are we not teaching civics in school anymore? or does everyone simply forget civics?

Biden won because he got the most electoral votes.
twitter.com/i/events/15172…
But what if there were massive fraud? if the Democrats actually stole the election?

The answer is still "Biden won because he had the most electoral votes" according to the law.

There is no "Trump actually won". That requires rejection of the concept of "rule of law".
It's really no different than 2016 when some Democrats claimed Hillary actually won because she received more of the popular vote.
No, we live in a system of "rule of law", and Trump won the most electoral votes, and that's all that matters.
Read 18 tweets
Apr 20
Poor Netflix stock dropped 'cause their subscriber growth stopped. I thought I'd create a thread of things I've enjoyed on Netflix.

To start with, the [subtitled] "Servant of the People", staring comedian Volodymyr Zelenskyy as the president of Ukraine. Uh ... timely? Image
Space Force season 1 was fun. Season 2 was ass. It got low ratings by critics, but they were wrong (about Season 1). It was quirky and weird with really fun characters. Don't bother with the second season, though. Image
"Russian Doll" was bizarrely original. It's totally not anything like "Groundhog Day".

I haven't seen Season 2 yet, but Season 1 was pretty awesome. [scifi?] Image
Read 15 tweets
Apr 7
There is no objective definition of "disinformation". Instead, "disinformation" is only "things you disagree with". You really can't have a discussion of "disinformation" without discussing Hunter Biden's laptop.
Hunter Biden's laptop is garbage, of course. But it's not "disinformation" according to the definition. The contents appear true, some have been verified, although they are misleading.
Yet, major news outlets dismissed it as disinformation -- even as verified that the most salacious of the emails was authentic.
Read 5 tweets
Apr 6
So anyway, to revisit this topic. This "Bitcoin is a battery" topic is one of those "partisan truths", with both sides making absurd comments. Cryptobros who made the claim are absurd, but so are many of the overly partisan responses.
Wind farms and solar farms produce energy at inconvenient times and inconvenient places. They need batteries to work. The lack of batteries means they can produce more power than the grid needs, causing electricity prices to go negative sometimes in California and Portugal.
Bitcoin miners chase wherever power is cheapest. Instead of discarding older (less efficient) mining boxes, they can just send them to California or Portugal to suck up the excess power, thus replacing the need for batteries.
Read 7 tweets
Apr 6
FYI:
1. there was a fox outside the Capitol biting politicians and tourists
2. it was a mother with baby kits
3. she tested for rabies and was euthanized
4. the kits are being cared for
I tweet this because I got tired of all the fragments of the story hitting my timeline, so I thought I'd tweet all the info.
I chose "tested AND euthanized" to avoid complications. But since you mention it, it's "euthanized IN ORDER TO test".

The only reliable test uses brain tissue. QED: the animal must be killed first.
Read 4 tweets
Mar 6
For over a year now:
1. Mike Lindell makes big claims
2. that make no sense
3. that he fails to come through on as promised

...and yet, this never seems to affect his support.
He claimed to have "Absolute Proof" votes were flipped by hackers. He never produced the proof, and why little hints he did show, make no sense. (Shows IP addresses of county websites that aren't involved in elections).
After failing to deliver the promised "Absolute Proof", he then promised a lawsuit going all the way to the supreme court, which went nowhere, because it made no legal sense.
Read 4 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(