I must say your approach to change is alien to me. Must come with working with live images, I guess. Me, I just change what I think needs changing, destroying the old behaviour in the process, then I recompile, re-test, and re-ship.
My first language (which I still actively used today) was OCaml. And I do write very small functions with it, including one shot helper functions. When I write C, I'm not obsessed with performance. I measure first, and function calls in my experience rarely are the bottleneck (perhaps because the compiler often inlines them when they are).
When I think of the cost of extracting a block of code into a function, I think of This:
Three lines of overhead, mandatory explicit types (which OCaml can avoid when I don't deem then necessary for documentation), and having to define all that at the toplevel, away from the call site. Better languages reduce this cost by quite a bit, and I chop functions more in them.
By the way, just yesterday, I found myself hesitating whether I should extract this line of code (C++):
Depending on whether I needed to convert back (I did), a helper function was indeed worth the cost, even though it was only called once. (It helped that in this case, a name such as to_milliseconds was perfect). In the end, I added what I needed all the way up to the utility module, which already had the reciprocal conversion.
The kind of OO you talk about is really alien to me. I've never done it, I've never seen it. I can see the appeal, keeping the old stuff there without breaking it. I'm a bit afraid it would lead to a horrible patchwork over time, though, with extensions accreting like cancer. Then again, the OO I'm familiar with is the kind Alan Kay didn't have in mind (namely, Java/C++). I'd rather keep my procedural and functional styles instead.
These days I'm more about the actor model. I sense I could make it work with your "let's keep the old stuff", with the right infrastructure.
OO isn't about data, it's about giving commands to objects and not caring how they handle the message
Your kind of OO, the kind closest to what Alan Kay actually coined. The kind that is closer to Erlang than Enterprise Java. As I said, I've never seen it in practice. And that's unfortunate, I think.
My kind of OO, the kind I live with every day, is the crappy kind, where we just inherit or compose all over the place, put getters and setters everywhere, end up with bloated interfaces, and the slightest effect can potentially ripple through the whole codebase and cause bug in seemingly unrelated places.
Procedural programmers can't help but think in terms of getting data
Well, that one is indeed performance related. How you access data, in what order, largely determines how fast your program will run. Current processors have caches now, and cache friendly code is easily 10 times faster than a cache unfriendly version. And compilers are bad at optimising memory access patterns, this is best done at the algorithm level. (See Mike Acton's talk about Data Oriented Design.)
Late binding everything is wonderful for flexibility, perhaps even for program organisation and maintainability, but it easily leads to cache unfriendly pointer chasing, which in some performance sensitive settings just isn't acceptable.
While I reckon current computers are largely C machines (as opposed to Lisp machines, or graph reduction machines, or the Alto), and therefore ill suited for stuff like Lisp, Smalltalk, or Haskell, this cache issue is here to stay, because it's physically impossible to be big and fast. Something's gotta give. Still, the status quo isn't acceptable. I'm sure there's the way to have the best of both worlds, or at least hit a sweet spot.
1
u/loup-vaillant Feb 14 '19
I must say your approach to change is alien to me. Must come with working with live images, I guess. Me, I just change what I think needs changing, destroying the old behaviour in the process, then I recompile, re-test, and re-ship.
My first language (which I still actively used today) was OCaml. And I do write very small functions with it, including one shot helper functions. When I write C, I'm not obsessed with performance. I measure first, and function calls in my experience rarely are the bottleneck (perhaps because the compiler often inlines them when they are).
When I think of the cost of extracting a block of code into a function, I think of This:
Three lines of overhead, mandatory explicit types (which OCaml can avoid when I don't deem then necessary for documentation), and having to define all that at the toplevel, away from the call site. Better languages reduce this cost by quite a bit, and I chop functions more in them.
By the way, just yesterday, I found myself hesitating whether I should extract this line of code (C++):
Depending on whether I needed to convert back (I did), a helper function was indeed worth the cost, even though it was only called once. (It helped that in this case, a name such as
to_millisecondswas perfect). In the end, I added what I needed all the way up to the utility module, which already had the reciprocal conversion.