Live data from Hacker News

The compiler will optimize that away

blog.royalsloth.eu

171–180 of 329 posts

Re: The compiler will optimize that away

#171
post #79

The implicit premise of the article seems to be that all software has to be heavily optimized. This is completely wrong. All the languages mentioned in the article are still around because it doesn’t matter how performant 99% of code is. For the 1%, we can think about cache misses, SIMD and data parallel approaches. In my experience this is totally possible and not too hard, but has the enormous downside of making th…

I disagree. Almost all software I use these days is absurdly slower than it should be and probably a massive drain on collective productivity. I have ssd, fast internet, 64gb ddr4 etc, almost everything I do should be impercetibly instant but instead takes seconds and even minutes. Yeah of course most of that slowness is not even because of ignorance of the low level stuff but complete disregard of performance aspect…

> Sure developer time costs, but this cannot actually be the reason.

It totally is because we've abstracted the cost of software engineering unto the hardware.

Back in the 90s, people had to basically beg for memory when writing software while modern development is built on the theory of getting the fastest delivery speed at the cost of performance. We outsource the cost of software unto millions of customer's hardware and it's never coming back because going to market quick makes you money.

Re: The compiler will optimize that away

#173
Did you also notice how the need for interface and type abstractions goes away? If you have a function that sum()'s a list of numbers, you can use that to sum() any of the Ant's members by passing a ref to the list. Otherwise you have to write AntSummer classes that take Ant (and all the children of Ant's class).

It does occur to me that there's a certain type of programmer for whom this is obvious. And that type of programmer was not using classes anyway for the reasons above. For that programmer, objects are a massively overused hammer in software design. I know those types, and they're very good. It might be there's too much brainpower wasted in designing object hierarchies that could go to exploring functionality or producing value. Or it might be coincidence.

I'm not really that guy necessarily, but for simply reasons of communicating and comprehending designs I always thought objects more than a few members were just plain wasteful. There just never seemed to be a reason to have all those mutable hidden member variables unless it was to abstract something like a data structure.

Re: The compiler will optimize that away

#174

Earlier quoted context omitted.

Well, you really picked the worst representative with awt/swing. I'd say Qt or even classic VB6/Delphi are great examples for OOP gui development.

Cocoa has been a great OOP-based UI framework forever. The key is that it doesn't use inheritance and has messaging ( https://wiki.c2.com/?AlternateHardAndSoftLayers ).

> The key is that it doesn't use inheritance

Cocoa is literally based on inheriting from NSView (which itself inherits from NSResponder)

https://developer.apple.com/documentation/appkit/nsview

Re: The compiler will optimize that away

#175

Earlier quoted context omitted.

> The relations object doesn't correspond to a real domain object anymore. “relationship” is a noun describing a real feature of the domain, and thus is a real domain object.

You could say that about anything you construct in your model though? Stops being OO if it's not somehow similar to an admittedly vague concept of what an object is, surely? I could write the whole thing as an ECS and call all the objects systems or components, and then they are nouns in the domain?

ECS can definitely be built in an OO fashion.

Re: The compiler will optimize that away

#176

Good article. My own thinking when coding performance is also towards data oriented approaches. For example Bevy in Rust. If stuff needs to be fast, it needs to be in cache. To do that, have everything nicely packed so you only ask for a chunk as often as you need. Then when you need it, it's already there. Thing about old fashioned OO is it's often fine enough for your run-of-the-mill CRUD app. If you look at the la…

> as opposed to OO where you have the data declared next to the functions that mutate it.

In the popular OO languages. As usual, the Common Lisp Object System is always worth a look. You have classes that encapsulate data, and then you have "free" generic functions (well, methods that implement those generic functions) that operate on that data.

Re: The compiler will optimize that away

#177

Earlier quoted context omitted.

Cocoa has been a great OOP-based UI framework forever. The key is that it doesn't use inheritance and has messaging ( https://wiki.c2.com/?AlternateHardAndSoftLayers ).

> The key is that it doesn't use inheritance Cocoa is literally based on inheriting from NSView (which itself inherits from NSResponder) https://developer.apple.com/documentation/appkit/nsview

That's if you want to make a custom view, which very often you don't. Placing default views in a window and receiving events/values from them doesn't use inheritance, instead using composition and delegate patterns.

UIKit lost some of the convenience features like bindings when it shrunk to fit on phones, which might be why people got annoyed enough to invent entirely new UI frameworks.

Re: The compiler will optimize that away

#178
post #42

> So far, the only programming language I know of that supports this type of crazy data transformations is JAI, As far as I know JAI is indeed the only language that explicitly lets you switch between AoS and SoA with one bit, but the APL family of languages - (APL, J, K, Shakti, and a couple more) has basically - for 60 years no - taken the "data oriented" SoA approach for storage, and provides the language support…

By coincidence, there is a new Nim blog post demonstrating exactly that. With the same ant example. https://nim-lang.org/blog/2021/05/01/this-month-with-nim.htm...

Re: The compiler will optimize that away

#179

Earlier quoted context omitted.

Well, you really picked the worst representative with awt/swing. I'd say Qt or even classic VB6/Delphi are great examples for OOP gui development.

How about JavaFX? Swing has been old hat for years now.

I haven't touched java gui code in almost a decade, but didn't they suddenly pull a 180 on JavaFX a few years ago?

Re: The compiler will optimize that away

#180
The real answer is you almost never need to solve this silly problem. If your data is static, why are you counting through arrays? If its dynamic, your n is probably low enough it doesn't matter or you're using some better data structure than an array.

If you do hit this kind of problem its usually in games (lots of dynamic user generated content) and even then the n is usually negligible. The parts where this does matter are already very data oriented. (Although not just in the way the article implies. Think vertex buffers and bitmaps.)

Point is, languages could probably add some kind of column oriented type of array and compilers could efficiently loop through them but it probably wouldn't really help all that much.

Post reply on HN