Live data from Hacker News

Applying the Linus Torvalds “Good Taste” Coding Requirement

medium.com

261–270 of 302 posts

Re: Applying the Linus Torvalds “Good Taste” Coding Requirement

#261
post #80

Earlier quoted context omitted.

Actually, I find the double pointer version easier to understand, and incidentally it is also the way always wrote this in C. And I pitied the pascal programmers who had to use the original version. 'Simplify so a fool can understand your code, and you will have fools editing it.'

Pascal has references and pointers too so why would they not be able to do it in a very similar way?

In the original pascal pointers/refs came only out of new (AFAIR), you couldn't point into structures or to local variables. That makes this trick impossible.

'Modern' 'pascals' were different.

Re: Applying the Linus Torvalds “Good Taste” Coding Requirement

#262
post #97

For my money, Linus's example of "good taste" gives up rather a lot of clarity to achieve succinctness. The original is simple and clear. His preferred version is shorter, but also harder to understand because of its use of a complicated indirection. And that's not good taste. It's just showing off. “Programs must be written for people to read, and only incidentally for machines to execute.” ― Harold Abelson, Structu…

I think the specific example can create a distraction because of the use of indirection, but that there is a more general point to discuss: at what point is a chunk of code "too clever?" One argument is that code should be written so that junior or average (or even below average) developers can be put to work on it. Another view is that part of a junior developer's learning experience ought to include not shielding h…

'cleverness for its own sake' often makes it into standard practice later.

And I seriously fail to see the 'for its own sake' here. This cleverness reduces the number of moving parts, does the 'dont repeat yourself' and thus reduces ways modifications of the code could break it due to overseeing a case.

I just shuddered to think how this would be done in java - with a LinkUpdater interface, and a RootLinkUpdater and ElementLinkUpdater, and one instantiation per iteration, and suddenly we have a lot of code around to keep the active code's function simple - to a point where it is completely pointless because of adding a lot of machinery. (And java does collections differently anyway.)

Re: Applying the Linus Torvalds “Good Taste” Coding Requirement

#263
post #257

Earlier quoted context omitted.

It is an error though if your code SEGFAULT on NULL head (and this one does). I wouldn't care, but if you claim to be defensive, go full monty.

> It is an error though if your code SEGFAULT on NULL head (and this one does). There is no "SEGFAULT" in kernel code. SIGSEGV is a signal, which is only used at user-level. NULL dereference in the kernel results in an "oops". I believe it is also assumed in their code that "entry" is not going to be NULL, meaning "if (head == entry)" will never succeed if head is NULL.

The code crashes if head is NULL, regardless of entry.

Re: Applying the Linus Torvalds “Good Taste” Coding Requirement

#264

I've been told many times that it's better to eliminate edge cases. I still don't really believe it as a universal law. When explaining the algorithm "remove an element from a linked list" to someone else, I would say "starting at the head, go along the list until you find the element; then delete the element". When explaining the algorithm "delete an element from a linked list", I would say "if you're at the head, u…

> It's so naturally a two-case problem that I'd be really surprised if anyone came up with the one-case answer first.

[Raises hand] I always did it Linus' way in C (way before him); I don't remember if I ever had the need in assembly before.

Re: Applying the Linus Torvalds “Good Taste” Coding Requirement

#265
post #98
post #2

I was given a piece of advice very early on in my career that I've always been grateful for, which is fundamentally the same as this. IF and FOR are both code smells. One case of this is just simplifying loops with some functional goodness var listOfGoodFoos = new List (); for(var i = 0; i VS return listOfAllFoos.Where(x => x.IsGood); But perhaps a more interesting point is it can also be a a sign of DRY gone wrong -…

It's not simplifying it though, it's just hiding the complexity in syntactic sugar. I prefer the first way of doing things vastly over the second. Yeah, it's more code, but it's also more or less "what is actually happening", instead of an euphemism which has to be unpacked.

The first example is code duplication, and almost every line is suspecious.

    var listOfGoodFoos = new List(); // is listOfGoodFoos a good name?
    for(var i = 0; i
The second example is obviously correct, and highlights the condition.

A quote from Tony Hoare comes to mind:

There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies.

Re: Applying the Linus Torvalds “Good Taste” Coding Requirement

#266
post #205

Earlier quoted context omitted.

Counterpoint: test code is also code and when unit test tyrants rule a team it can easily break down into a mess of maintenance (which suddenly more than doubles).

Speaking of good "taste" you could apply your "taste" to what are worthy tests and what are not (ie adding just maintenance). The fact of the matter is you need some sort of testing to happen or some sort of proof that your code works on a continuous basis and if you don't have that to happen IMO I'm not going to say it is good code particularly when it is based solely on one persons opinion of what is good looking c…

I don't down vote, and in fact only recently noticed I could. I don't know who down voted you.

To the other points, "no tests" is the other extreme from "test everything." I find both views are unacceptable in practice.

Re: Applying the Linus Torvalds “Good Taste” Coding Requirement

#267
post #262
post #97

Earlier quoted context omitted.

I think the specific example can create a distraction because of the use of indirection, but that there is a more general point to discuss: at what point is a chunk of code "too clever?" One argument is that code should be written so that junior or average (or even below average) developers can be put to work on it. Another view is that part of a junior developer's learning experience ought to include not shielding h…

'cleverness for its own sake' often makes it into standard practice later. And I seriously fail to see the 'for its own sake' here. This cleverness reduces the number of moving parts, does the 'dont repeat yourself' and thus reduces ways modifications of the code could break it due to overseeing a case. I just shuddered to think how this would be done in java - with a LinkUpdater interface, and a RootLinkUpdater and…

I agree with you, about this specific example and in general.

When I look back on my career, often when I've said something is "clever for its own sake" was only clever because of a lack of understanding on my part, and rarely for its own sake, outside of toys and obscurity competition where such cleverness is the point.

Re: Applying the Linus Torvalds “Good Taste” Coding Requirement

#268

Earlier quoted context omitted.

I agree with you that moving the conditional to the beginning as an early exit keeps things simple, and while I don't see anything unusual about a 'while' loop and feel they have their place, this 'for' definitely works well. I would make one small tweak, replacing this line prev->next = prev->next->next; with prev->next = entry->next; Just makes it a bit more straightforward to understand (as well as infinitesimally…

Yes, I'd be ok with a `while` that checked for the end of the list: https://news.ycombinator.com/item?id=12798192 I really try not to be a nazi about this sort of thing. Very few things matter enough to get into a HN conversation about "taste".

Totally, it's not about the one right way to do something. I do think there's some value in putting thought into how to write.. maybe "clean" code would be a less charged word than tasteful.

Re: Applying the Linus Torvalds “Good Taste” Coding Requirement

#269
post #246

Earlier quoted context omitted.

See what I already wrote. This is like marketing research - what do you believe, what people tell you or the data about what they actually do? Because the data say what I already wrote. So you might as well interpret this as "Linus is a very humble guy" and have better support from the data. Or, alternatively, you can believe that a really mean person who doesn't care about others and behaves badly still managed to h…

I don't understand what this has to do with refuting the original claim: > Ultimately I think Linus's contributions to Software are pantheon, but he should not be looked to for imitation or lessons. His lessons for success are detrimental to the vast majority of software engineers. You're not supplying any examples others can learn from or benefit from imitating, you're just asserting they must exist.

Uhm... this is again backwards. I'm not making any claims - I'm responding to others who do. And I did (still) provide evidence: The Linux kernel project itself. Instead of individual anecdotes or some carefully selected email or sentences taken out of context I point to the whole project as the final outcome measurement. See what I wrote?

Re: Applying the Linus Torvalds “Good Taste” Coding Requirement

#270

Earlier quoted context omitted.

I get what you are saying and I agree somewhat, but there are also some lessons to be learned from Linus and things to consider. I especially agree that many lesser talented people use his behavior as a justification for their own. I disagree that at least some of his lessons or behavior is detrimental. A good realization in life that many of us have is, "Most people are wrong about most things most of the time." Thi…

I can see where you are coming from, but the problem with speaking plainly and directly in all cases is that it can run into some pretty hard cultural boundaries. What you say and what people will interpret you as saying can be quite different. I struggled for a long time to understand that, so let me explain. The way this seems to work around here (I'm a Canadian, and I've worked in the US, too) is that it is just f…

Yes, in part what I was saying that in some cultures, people are more openly critical. It just is accepted, and no one gets too offended unless they are from another culture. What you are saying about the inability in US/Canadian culture to be upwardly critical or even critical sideways is entirely true. It is also such a silly thing and really makes the workplace unpleasant for many people, more than someone calling my code shit might do.

As someone who grew up in multiple cultures and lived in other cultures (Toronto, Canada among a few others), I see all too clearly what it means to cross or run-up against cultural boundaries. I've had to explain to girlfriends (outside my culture) for instance not to get offended by my family (non-American) and the things they will say. Quickly, they come to realize that despite the sometimes harsh sounding words, culturally my very blunt family is much warmer than anything they encountered before.

I am also well aware of what criticism means in different cultures and workplaces and I do not struggle with what you described. Your advice about keeping all that in mind is solid from a practical perspective. What I am saying has nothing to do with advising or advocating people to be like Linus or like me. Rather I am saying a few important things - understand the value of bluntness, the reasons behind it, don't be harsh for the sake of being harsh, pretending is silly, and that I am a firm believer in honesty.

I do value knowing what the culture norms are, but I try not to let myself be entirely bound in life by them. I have worked long enough and put myself in situations not to work with people who make me play stupid games or diplomatic twister. People should not discount the value of being direct just because it is against their cultural norms. Further, they should see that people from other cultures or other mindsets might have another point of view worth considering. As a result of just being honest, I find in most situations my communication is perceived clearly. I know this because people tell me exactly that and the results seem to match.

There was an interesting article recently in the NYT or Washington Post or something else big about the UN Ambassador for Israel and what gets said to him from enemy countries behind close doors (nice things, blunt things) vs. the crazy rhetoric some of the same ambassadors use when addressing what he calls the "public UN." In part, one of the points he was making is that the real work was getting done behind closed doors and the rest was mindless gesturing and show for the people back home in various countries.

Regarding Linus specifically, what he says can be taken (and is) sometimes as harshness for the sake of it. That does not mean there is not passion, value, truth, and other things to be found. Notice though that the truly valuable things Linus says in harsh ways are nearly always backed up by facts. If Linus says someone's code is stupid, often he points out exactly why and where instead of wasting time trying to be diplomatic about a bad commit. Taking this to the extreme where you don't provide any reason, feedback, and facts is a big problem. People who do this are not being honest or blunt, they are just being jerks and there lies part of the difference.

Perception is important and that's something people forget. I get that people are sensitive, caught up in their culture, yet at some point I would advise people to think with their brains and grow up. People like to do the same thing I described in the UN - gesture using their status, position, titles. That is a dumb thing that stands in the way of getting things done and what many people would perceive as being a good person. If a CIO wanted to fire me because something I said hurt his/her feelings, that's fine with me and not a place I want to work. I would never purposely say hurtful things to someone, at least things that were not true and certainly not without a concrete reason. My view though is a bad prescription for many people, so it's important to also understand that.

It's also worth noting that there is a time and a place for criticism, which is not all the time. More often than not, instead of whining and blowing up at someone, the situation will correct itself if no one pretends or lies to provide encouragement otherwise. At some point you may need to still intervene, but it is contextual. I'll never tell someone who is doing a bad job a bunch of positive things to encourage them for the sake of it. Likewise, when they start doing an actual good job, I will thank them for it. Linus perhaps could use a little more positive reinforcement. I guess he's OK with how he is, so be it.

I am not afraid to sound insulting here by saying that I think it's a sign of low intelligence if you cannot step outside of yourself at times. Obviously it's hard to do this all the time. People really get so caught up in doing what is expected rather than thinking for themselves. This conjures notions of "sheeple" and living a false narrative. I find these things far more revolting than what anyone could say to me with simple words, other people believe otherwise. I learned long ago there is no way you can make everyone like you, but you can respect everyone at least on basic levels of behavior which does not necessarily mean bowing to their cultural norms and emotions, rather simple, basic humanity.

You mention some examples of social tap dancing. While doing consulting, I had to become the master of this and it's rather a necessary skill in this world that I hate. What people are doing by saying things like, "That doesn't look right to me" is usually lying by omission, acting passive aggressive, or simply communicating poorly by garbling the message. To be honest, this sometimes really annoyed me in Canada when people would pass-off passive aggressive behavior as "polite" behavior. Of course my own culture skews this perception and most of the time. My solution was to take my own advice - understand their point of view, don't be offended, and move forward to what's real.

Generally, I try to always provide facts, reasons, clarity, and to keep calm. I expect the same back, as it should be. I would rather live a good, honest life and not live in a fantasy world. One semi-effective test is that if you have to ask yourself if you are being an a-hole, you are the a-hole. Surprisingly, I have only actually yelled at anyone seriously once in my career and it was related to something just about anyone would react the same (racism). Being honest and blunt doesn't mean you have to treat people poorly, yell, or go out of your way to be negative. On the contrary, I tend to compliment people more because I am not afraid to be open.

I find being open breaks down a lot of important barriers at times. In my personal life, this often leads to a lot of "Thank yous" and being the go-to friend for advice, confessions, problems, and more. In the workplace, people feel comfortable bringing tough and embarrassing problems to me because they know they will get an honest and constructive answer. I often felt crippled at points in my career when I got polite, useless feedback. I can't express how many problems in life or programming I have solved by simply telling it like it is. Quite often, it has nothing to do with dropping f-bombs. Sometimes I just tell someone that I feel stupid and need help, and I am happy when others reciprocate. As you can see, this is probably one area where Linus and I differ, but I can't help but laugh at the reactions he gets from ridiculous people that don't want to admit their own faults. I have many faults and I freely admit them because I want help.

If I had to actually give a piece of advice here, it would be to just be yourself and figure out what you value. Everything you do should be working towards that. If someone stands in your way, don't run them over, just put yourself in a better position - find a new job, move, cut them off, be the better person, prove your points with facts, do whatever you need to get past it while staying a good person. Lying to yourself is a hard thing. Being critical is not being cynical, it is being honest if you approach it with a clear mind. This is all often at odds with tech culture and it has admittedly hurt me in a few cases. But I feel alright with myself and that is success for me.

Post reply on HN