News for hackers. Stuff that matters.
Re:Low Hanging Fruit of Programming Language Design by ajmurmann on Wednesday November 22, 2017 @11:02AM (#15757789)
Sandi Metz said in one of her talks that wrong abstractions are worse than duplication and we just tell new developers about duplication because it's the only thing they understand. Strongly agreed.
Re:Low Hanging Fruit of Programming Language Design by catnaroek on Wednesday November 22, 2017 @07:37PM (#15761929)
Most programmers wouldn't know an abstraction if it hit them in the face. In fact, I highly doubt that most existing technology stacks allow you to build any abstractions at all, in the original sense of functionality so self-contained that a user can't distinguish it from a programming language primitive, not just syntactically, but also semantically. In particular:

(0) If you need to know or care about its implementation details when you use it, it's not an abstraction.

(1) If unrelated ad hoc cases are hardcoded together into a single procedure, it's not an abstraction.

(2) If it needs fifteen tunable parameters, some combinations of which don't even make sense, it's not an abstraction.

At some point in time, programmers discovered that selection (if, switch, pattern mathcing, whatever) could be replaced with dynamically dispatched first-class procedure calls. Since then, they haven't stopped making their code more “abstract” by making their control flow impossible to follow. Alas, this isn't real abstraction, because it doesn't achieve the intended purpose of reducing the number of things you have to keep in your head simultaneously.

So, rather than blaming “wrong abstractions”, I'd blame “not real abstractions”.

Re:Low Hanging Fruit of Programming Language Design by com2kid on Wednesday November 22, 2017 @07:55PM (#15762001)
> In fact, I highly doubt that most existing technology stacks allow you to build any abstractions at all, in the original sense of functionality so self-contained that a user can't distinguish it from a programming language primitive

Two of the most popular languages out there, C++ and JavaScript, are both great at this.

Sometimes, too great.

Re:Low Hanging Fruit of Programming Language Design by catnaroek on Wednesday November 22, 2017 @08:00PM (#15762025)
Are you serious? How do I define complex numbers (just to give one example) in JavaScript that actually behave like, you know, complex numbers? Recall that:

(0) The usual symbol for complex number addition is +.

(1) The operation isn't associated to any individual complex number (i.e., it's not an object method), but is rather an intrinsic part of the algebraic structure of the complex numbers.

(2) Complex numbers don't have a physical object identity in memory.

C++ fares a little better than JavaScript, but not a lot better.

Re:Low Hanging Fruit of Programming Language Design by com2kid on Thursday November 23, 2017 @02:32AM (#15763482)
The major JS frameworks look like languages onto themselves. JavaScript lacks operator overloading, so there are some limits, but it is quite possible to turn JS into something very unrecognizable.

C++ templates allow for almost anything. I have seen incredibly strange things done to the language with templates. Since Templates can be used to parse, and execute, entirely different programming languages, it is hard to imagine a level of abuse to which C++ templates are not amenable.

Re:Low Hanging Fruit of Programming Language Design by catnaroek on Thursday November 23, 2017 @03:00AM (#15763587)
> The major JS frameworks look like languages onto themselves (...) it is quite possible to turn JS into something very unrecognizable.

That doesn't mean anything. With enough determination, anything can be turned into “something very unrecognizable”. Heck, sometimes the results are relatively pleasant even: http://libcello.org/ . But, if a language doesn't allow you to define basic abstractions like complex numbers (not to mention slightly more elaborate ones, like queues that are indistinguishable from one another if they contain the same elements in the same order), then that obviously reflects very poorly on its abstraction facilities.

> C++ templates allow for almost anything. I have seen incredibly strange things done to the language with templates.

What you can't do in C++, however, is make your abstractions not leak. Every template library is one template specialization away from being broken. This is unlike languages that enforce their abstractions by more robust means, like parametricity and macro hygiene.

Re:Low Hanging Fruit of Programming Language Design by stcredzero on Wednesday November 22, 2017 @01:09PM (#15758982)
wrong abstractions are worse than duplication

This needs to be given a catchy phrasing and spread all across developer communities!

WTD == Worse Than Duplication?

WAAW == Wrong Abstractions Are Worse?

Re:Low Hanging Fruit of Programming Language Design by jonahx on Wednesday November 22, 2017 @01:54PM (#15759391)
It's a great principle and I reference it frequently, but as a catchy buzzphrase it has the potential to do as much harm as good: it's easy to abuse as an excuse for copy paste programming.

Duplication is still bad, and correct abstractions are still good.

Re:Low Hanging Fruit of Programming Language Design by djur on Wednesday November 22, 2017 @02:27PM (#15759682)
See also "premature optimization is the root of all evil", which I occasionally see stretched to include any kind of thinking about the performance characteristics of your code, even down to basic design decisions like data structures or algorithms.
Re:Low Hanging Fruit of Programming Language Design by grandalf on Wednesday November 22, 2017 @05:19PM (#15761187)
Great point. I've found that most codebases have some abstractions that work very well and others that work less well, and simply having awareness of this can help make the code far more readable.

For instance, one might say: "The way x is implemented works, but it's not quite the right abstraction, here's why". That is way more informative than saying it's simply the wrong abstraction or considering it good enough and ignoring its deficiencies.

Re:Low Hanging Fruit of Programming Language Design by gcatlin on Wednesday November 22, 2017 @03:05PM (#15760091)
Premature abstraction is the root of all evil.
Re:Low Hanging Fruit of Programming Language Design by kirkules on Thursday November 23, 2017 @04:04AM (#15763854)
Premature abstraction is pure mathematics
Re:Low Hanging Fruit of Programming Language Design by jonahx on Wednesday November 22, 2017 @01:51PM (#15759364)
Re:Low Hanging Fruit of Programming Language Design by gowld on Wednesday November 22, 2017 @05:59PM (#15761438)
DRY is not the same as adding layers of abstraction.
Re:Low Hanging Fruit of Programming Language Design by leakyabs on Wednesday November 22, 2017 @01:52PM (#15759371)
I feel this in my soul. I work on a JavaScript project now where sometimes two duplicate pieces of code are “refactored” into one function unnecessarily. Just because there are two similar lines doesn’t mean they need to be their own function/class/whatever, especially when it makes it harder to generalize later when you need similar code that DOESN’T make sense to lump in with that abstraction.

I keep having to simplify the code and it’s exhausting.