News for hackers. Stuff that matters.
Re:An Overwhelmingly Negative and Demoralizing Force by buggy6257 on Tuesday April 08, 2025 @12:36PM (#43623669)
> sometimes reducing it to a one line lambda.

Please don't do this :) Readable code is better than clever code!

Re:An Overwhelmingly Negative and Demoralizing Force by throwaway889900 on Tuesday April 08, 2025 @12:55PM (#43623883)
Sometimes a lambda is more readable. "lambda x : x if x else 1" is pretty understandable and doesn't need to be it's own separately defined function.

I should also note that development style also depends on tools, so if your IDE makes inline functions more readable in it's display, it's fine to use concisely defined lambdas.

Readablity is a personal preference thing at some point after all.

Re:An Overwhelmingly Negative and Demoralizing Force by gopher_space on Tuesday April 08, 2025 @05:33PM (#43626685)
My cleverest one-liners will block me when I come back to them unless I write a few paragraphs of explanation as well.
Re:An Overwhelmingly Negative and Demoralizing Force by ethbr1 on Wednesday April 09, 2025 @12:41AM (#43628919)
>> Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian Kernighan

https://github.com/dwmkerr/hacker-laws#kernighans-law

Re:An Overwhelmingly Negative and Demoralizing Force by johnnyanmac on Tuesday April 08, 2025 @09:13PM (#43627996)
Ymmv. Know your language and how it treats such functions on the low level. It's probably fine for Javascript, it might be a disaster in C++ (indirectly).
Re:An Overwhelmingly Negative and Demoralizing Force by banannaise on Tuesday April 08, 2025 @11:29PM (#43628643)
> "lambda x : x if x else 1"

I think what you're looking for is "x or 1"

Re:An Overwhelmingly Negative and Demoralizing Force by bluefirebrand on Tuesday April 08, 2025 @12:50PM (#43623824)
Especially "clever" code that is AI generated!

At least with human-written clever code you can trust that somebody understood it at one point but the idea of trusting AI generated code that is "clever" makes my skin crawl

Re:An Overwhelmingly Negative and Demoralizing Force by Terr_ on Tuesday April 08, 2025 @09:00PM (#43627932)
Also, the ways in which a (sane) human will screw-up tend to follow internal logic that other humans have learned to predict, recognize, or understand.
Re:An Overwhelmingly Negative and Demoralizing Force by ben_w on Wednesday April 09, 2025 @06:26AM (#43630616)
Most devs I've worked with are sane, unfortunately the rare exceptions were not easy to predict or understand.
Re:An Overwhelmingly Negative and Demoralizing Force by vkou on Wednesday April 09, 2025 @02:58AM (#43629534)
Who are all these all these engineers who just take whatever garbage they are suggested, and who, without understanding it, submit it in a CL?

And was the code they were writing before they had an LLM any better?

Re:An Overwhelmingly Negative and Demoralizing Force by arkh on Wednesday April 09, 2025 @04:30AM (#43630044)
> Who are all these all these engineers who just take whatever garbage they are suggested, and who, without understanding it, submit it in a CL?

My guess would be engineers who are "forced" to use AI, already mailed management it would be an error and are interviewing for their next company. Malicious compliance: vibe code those new features and let maintainability and security be a problem for next employees / consultants.

Re:An Overwhelmingly Negative and Demoralizing Force by jcelerier on Tuesday April 08, 2025 @08:15PM (#43627731)
Who says that the one line lambda is less clear that a convoluted 10-line mess doing dumb stuff like if(fooIsTrue) { map["blah"] = bool(fooIsTrue); } else if (!fooIsTrue) { map["blah"] = false; }
Re:An Overwhelmingly Negative and Demoralizing Force by johnnyanmac on Tuesday April 08, 2025 @09:19PM (#43628023)
My experience in unmanaged legacy code bases. If it's an actual one liner than sure. Use your ternaries and closures. But there is some gnarly stuff done in some attempt to minimize lines of code. Most of us aren't in some competitive coding organization.

And I know it's intentional, but yes. Add some mindfulness to your implementation

Map["blah"] = fooIsTrue;

I do see your example in the wild sometimes. I've probably done it myself as well and never caught it.

Re:An Overwhelmingly Negative and Demoralizing Force by n4r9 on Wednesday April 09, 2025 @05:44AM (#43630446)
Are you telling me you've never seen code like this:

  var ageLookup = new Dictionary<AgeRange, List<Member>>();
  foreach (var member in members) {
    var ageRange = member.AgeRange;
    if (ageLookup.ContainsKey(ageRange)) {
      ageLookup[ageRange].Add(member);
    } else {
      ageLookup[ageRange] = new List<Member>();
      ageLookup[ageRange].Add(member);
    }
  }
which could instead be:

  var ageLookup = members.ToLookup(m => m.AgeRange, m => m);
Re:An Overwhelmingly Negative and Demoralizing Force by davidgay on Wednesday April 09, 2025 @11:32PM (#43640358)
I'm of the opinion that

  var ageLookup = new Dictionary<AgeRange, List<Member>>();
  foreach (var member in members) {
    ageLookup.getOrCreate(member.AgeRange, List::new).add(member);
  }
is more readable in the long-term... (less predefined methods/concepts to learn).
Re:An Overwhelmingly Negative and Demoralizing Force by n4r9 on Thursday April 10, 2025 @03:28AM (#43641551)
Where is `getOrCreate` defined? Is it a custom extension method? There's also a chance we're thinking in different languages. I was writing C#, yours looks a bit more like C++ maybe?

Readability incorporates familiarity but also conciseness. I suppose it depends what else is going on in the codebase. I have a database access class in one of my solutions where `ToLookup` is used 15 times; yes you have to learn the concept, but it's an inbuilt method and it's a massive benefit once you grok it.