News for hackers. Stuff that matters.
Re:The Wrong Abstraction (2016) by amelius on Friday July 20, 2018 @11:48PM (#17580598)
There is a quote by Linus Torvalds that is relevant here:

"Bad programmers worry about the code. Good programmers worry about data structures and their relationships."

Re:The Wrong Abstraction (2016) by bch on Saturday July 21, 2018 @01:32AM (#17580830)
"Show me your flowchart and conceal your tables, and I shall continue to be mystified. Show me your tables, and I won't usually need your flowcharts; they’ll be obvious." -- Fred Brooks, The Mythical Man Month (1975)
Re:The Wrong Abstraction (2016) by mpweiher on Saturday July 21, 2018 @04:58AM (#17581332)
Yep. And this is why our industry's decision to focus on essentially procedural abstractions for our interfaces is...problematic.
Re:The Wrong Abstraction (2016) by jstimpfle on Saturday July 21, 2018 @07:51AM (#17581688)
Let me offer a different interpretation: That's why it doesn't matter so much if you're doing code in a procedural or functional way. If your data structures are wrong, the code will be bad, period.
Re:The Wrong Abstraction (2016) by mpweiher on Saturday July 21, 2018 @10:28AM (#17582097)
Exactly.

To clarify: when I wrote "procedural abstractions", that included functional.

Re:The Wrong Abstraction (2016) by jstimpfle on Saturday July 21, 2018 @10:35AM (#17582121)
Ok, I guess I misunderstood you then. Maybe your comment was more in the spirit of "APIs should be less secretive about the shape of data they are maintaining internally?"
Re:The Wrong Abstraction (2016) by mpweiher on Saturday July 21, 2018 @02:10PM (#17583018)
Oh, it goes further than that. :-)

The assumption that data is something to be maintained internally, at best hidden behind an interface (a procedural one) and at worst "exposed" is so ingrained that it's hard to think of it any other way.

However, why can't we have "data" as the interface? The WWW and REST show that we can, and that it works quite swimmingly. With a REST interface you expose a "data" interface (resources that you can GET, PUT, DELETE, POST), but these resources may be implemented procedurally internally, the client has no way of knowing.

Re:The Wrong Abstraction (2016) by discreteevent on Saturday July 21, 2018 @03:10PM (#17583339)
The interface is the data. Have a look at Data Distribution Service or Eve programming (you may have seen them before). They go further than rest in that you can react to changes in the data model (rest is only half a protocol)
Re:The Wrong Abstraction (2016) by mpweiher on Saturday July 21, 2018 @03:28PM (#17583422)
Yeah, I am aware of Eve.

I've also done my bit, with In-Process REST[1] and Polymorphic Identifiers[2] for the "REST" half, and Constraint Connectors[3] for the "reacting" half.

[1] https://link.springer.com/chapter/10.1007/978-1-4614-9299-3_...

[2] https://www.hpi.uni-potsdam.de/hirschfeld/publications/media...

[3] https://www.hpi.uni-potsdam.de/hirschfeld/publications/media...

Re:The Wrong Abstraction (2016) by hiker on Saturday July 21, 2018 @10:08AM (#17582032)
Except that functional programming completely eliminates (yet still allows) concern no. 1 in the mentioned order -- state > coupling > complexity > code.

Not to mention the better expressive power for describing data structures with algebraic data types (just + and * for types really).

Re:The Wrong Abstraction (2016) by jstimpfle on Saturday July 21, 2018 @10:20AM (#17582072)
That's just not true. Functional programming does not eliminate state. You can't do computation without state. What fp does differently is it pushes state around like a hot potato. In my eyes that is about as problematic as OO (where you cut state in a thousand pieces and cram it in dark corners and hope nobody will see it).

If you make global arrays instead you will always have a wonderful idea of what your program's state is, and you can easily use and transform it with simple table iteration.

Re:The Wrong Abstraction (2016) by hiker on Saturday July 21, 2018 @10:37AM (#17582130)
> That's just not true. Functional programming does not eliminate state.

And yet it says so in the first sentence in the Wikipedia page for functional programming https://en.wikipedia.org/wiki/Functional_programming

>a style of building the structure and elements of computer programs—that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data.

But I'll take it that you don't have much functional programming experience.

Of course one can still go with a big global array and keep updating it in-place. A good programmer can write Fortran (or C in that case) in any language.

Re:The Wrong Abstraction (2016) by mpweiher on Saturday July 21, 2018 @02:19PM (#17583067)
At some point, you need to modify some state, otherwise your program/language is useless. And that's not me saying that, I am just quoting, or at least paraphrasing, Simon Peyton Jones:

https://www.youtube.com/watch?v=iSmkqocn0oQ

And of course a lot of so-called "functional" programs just outsource their state management to some sort of relational database. And the people talking about their creation will praise the state-less-ness of their creation. Unironically.

What can you do? ¯\_(ツ)_/¯

Anyway, more practically, the vast majority of workloads do not have computation as their primary function. They store, load and move data around. Computers, generally, don't compute. Much. For those workloads, a paradigm that tries to eliminate the very thing that the problem domain is about, and can only get it back by jumping through hoops, is arguably not ideal.

https://carlstrom.com/stanford/cs315a/papers/barroso00piranh...

Re:The Wrong Abstraction (2016) by Haegin on Monday July 23, 2018 @10:21AM (#17592939)
> avoids changing-state and mutable data.

This doesn't mean that functional programming eliminates state. Avoiding changing-state and mutable data is different and the Wikipedia article is referring to how functional programming doesn't mutate existing data, so you avoid the stale reference problems that can occur in OO languages.

Instead, the state is the current execution state of the program. Function calls are side affect free (except when interacting with the external world, which is a special case I'm not covering here). Because of this, the only way data can be communicated from one function to another is by passing it in when calling the function, or by returning it. This means the state is just the data local to the currently executing function, and any calling functions (though the data in that part of the state isn't available to the current function it's still in memory until the calling function returns).

Contrast this with procedural programming languages, where state can also be maintained in global variables, or object oriented languages, where objects maintain their own state with the system state being spread around the whole system.

Re:The Wrong Abstraction (2016) by jstimpfle on Saturday July 21, 2018 @10:53AM (#17582187)
Again, you can't do computation without state. The only question is how honest you want to be about it. And whether you put things in global tables or not is completely orthogonal to whether you mutate data or make new data.

And please, no beaten up buzz words and selling pitches needed.

Re:The Wrong Abstraction (2016) by andai on Saturday July 21, 2018 @04:26AM (#17581244)
I looked up the full text of the book, but couldn't figure out what tables mean in this context.
Re:The Wrong Abstraction (2016) by wazoox on Saturday July 21, 2018 @06:50AM (#17581566)
The quote comes usually with "data" instead of "tables" and "algorithms" instead of "flowcharts".
Re:The Wrong Abstraction (2016) by abdulhaq on Saturday July 21, 2018 @05:36AM (#17581421)
Row/column data such as you would find on mainframe accounting software
Re:The Wrong Abstraction (2016) by im3w1l on Saturday July 21, 2018 @04:54AM (#17581323)
I would assume database tables
Re:The Wrong Abstraction (2016) by opless on Saturday July 21, 2018 @04:56AM (#17581328)
I'm guessing s/tables/data/g
Re:The Wrong Abstraction (2016) by amelius on Saturday July 21, 2018 @06:26AM (#17581531)
Yes, and sometimes I feel this also holds in a way for user manuals.
Re:The Wrong Abstraction (2016) by emmelaich on Saturday July 21, 2018 @04:13AM (#17581203)
"Algorithms + Data Structures = Programs" is a classic book by Niklaus Wirth.

It was one of the first to emphasis data structures in addition to code.

There is a free pdf online[0] discussed on HN in 2010.[1]

(from wikipedia) "The Turbo Pascal compiler written by Anders Hejlsberg was largely inspired by the "Tiny Pascal" compiler in Niklaus Wirth's book."[2]

[0] http://www.ethoberon.ethz.ch/books.html

[1] https://news.ycombinator.com/item?id=1921125

[2] https://en.wikipedia.org/wiki/Algorithms_%2B_Data_Structures...

Re:The Wrong Abstraction (2016) by fourgoodboys on Saturday July 21, 2018 @07:47AM (#17581674)
To add a little of poetry, another quote: In fact, I'll take real toilet paper over standards any day, because at least that way I won't have splinters and ink up my arse.

From linus rants: https://www.reddit.com/r/linusrants/comments/8ou2ah/in_fact_...

Re:The Wrong Abstraction (2016) by jsharf on Saturday July 21, 2018 @03:14AM (#17581063)
I think you're just misusing that quote... At the end of the day, for any given datastructure setup, an algorithm still needs to be implemented. There's many ways to slice that pie, and depending on how you do it, that can cause a lot of saved time or misery for the engineers you work with.
Re:The Wrong Abstraction (2016) by tigershark on Saturday July 21, 2018 @03:04AM (#17581044)
Data structures and their relationship cannot express everything. SQL is not Turing complete if you don’t use CTE to introduce recursion. And I think that we all agree that SQL is perfect to work on data structures and their relationship.
Re:The Wrong Abstraction (2016) by Erlich_Bachman on Saturday July 21, 2018 @03:55AM (#17581146)
The original comment is on a completely different level of analysis. I think that if you know about Linus Torvalds, that you will agree that he knows what SQL is and how it differs from a turing-complete language. The point being made is much deeper and philosophical, and makes a lot of sense in complex systems.
Re:The Wrong Abstraction (2016) by johnny22 on Saturday July 21, 2018 @05:43AM (#17581442)
does he know how SQL works?
Re:The Wrong Abstraction (2016) by tigershark on Saturday July 21, 2018 @12:36PM (#17582551)
I “know” who is Linus Torvalds since when I installed my first Linux distribution on my 386sx 25mhz when I was 14 or so in 1995/6. I think he is very smart but sometimes I disagree with him and with his harsh way of relating with the rest of the world. Now, after a useless appeal on authority, would you mind to explain what is wrong with my opinion about data structures and relationships? I don’t really think that you can do everything just with data structures and relationships. If you think the opposite than please explain how you can do everything with something not Turing complete.
Re:The Wrong Abstraction (2016) by Erlich_Bachman on Sunday July 22, 2018 @02:46AM (#17585561)
> I don’t really think that you can do everything just with data structures and relationships.

No, you can't do everything with just data structures. Everyone knows this. 1st-year junior programmer knows this. It's obvious. The original question did not talk about this, you misunderstood the level of analysis it was aiming at.

The fact that SQL is not turing complete is a meaningless truism here, because Linus obviously did not mean that we should all start using SQL instead of C. The point he is making is that data structures are of much bigger importance to get right in order for the program to be good. Not just fast or just maintainable, or just easy to understand. But all of those things and many others.

Re:The Wrong Abstraction (2016) by majewsky on Saturday July 21, 2018 @07:00AM (#17581585)
"SQL is perfect to work on data structures" if and only if relational tables are the only data structure that you know.
Re:The Wrong Abstraction (2016) by jstimpfle on Saturday July 21, 2018 @07:55AM (#17581700)
Try to look at it that way: what isn't a relational table? Any data structure you can make is essentially a tuple of primitive elements. It may point to further data items, but still. Now, put equally shaped tuples in common tables, and you have a database.
Re:The Wrong Abstraction (2016) by hiker on Saturday July 21, 2018 @10:13AM (#17582047)
Trees, graphs?

Of course one can force anything into a relational database. The data analog of "Turing tarpit".

Ironically graph databases are way better for describing relations than relational databases.

Re:The Wrong Abstraction (2016) by jstimpfle on Saturday July 21, 2018 @01:51PM (#17582915)
> Trees, graphs?

Easily represented as a vertices-array and an edges-array. It's conventional to index the (directed) edges to optimize iteration over all edges from a given vertice. If you're being "sloppy", you can also represent edges as vector<vector<int>> (one array of destinations per source). This is more convenient but comes with the slight disadvantage that these arrays are physically separated (for example, you'll need two nested loops instead of only one to iterate over all edges).

Re:The Wrong Abstraction (2016) by tigershark on Saturday July 21, 2018 @12:43PM (#17582590)
At the same way that you can force everything in a deterministic or non deterministic Turing machine, depending from the problem. But something that is just looking at data and relationships, akin to a relational database, while extremely powerful, can’t solve every problem in the world. There are much better tools for that. And they have something more than just data and relationships.
Re:The Wrong Abstraction (2016) by jstimpfle on Saturday July 21, 2018 @10:28AM (#17582098)
Of course you can force anything in a graph database. But then you have to make special collection objects to iterate over all Foo items in your process. I guess you'll also need some kind of garbage collector.

> Ironically graph databases are way better for describing relations than relational databases.

How so?

Re:The Wrong Abstraction (2016) by tigershark on Saturday July 21, 2018 @12:40PM (#17582572)
You can force pretty much every data structure that I know in a table. That doesn’t mean that you can solve everything with a non Turing complete language. So, unless I’m badly mistaken, you’ll need something more than data and relationships to solve everything.
Re:The Wrong Abstraction (2016) by pjc50 on Saturday July 21, 2018 @06:08AM (#17581492)
The Linux kernel, Linus's lifetime project, is full of data structures and contains no SQL. Because it's completely inappropriate in that context.