4 ms·
I dunno. One could say that C string handling is "simple" (it's just byte buffers!) or that manual loops are "simpler" than proper iterator abstractions, but th
by chousuke 6y ago
I dunno. One could say that C string handling is "simple" (it's just byte buffers!) or that manual loops are "simpler" than proper iterator abstractions, but those are both constructs that are hideously error-prone in practice.
Perhaps it's the other way around and manual buffer management is actually the complex thing, since your application logic will have to involve a lot of code doing toil that isn't directly related to what you want to accomplish.
EDIT:
To expand a bit, I'm a huge proponent of simplicity; I think overabstraction is a massive problem with software nowadays. However, my thinking is that the problem isn't so much with the abstractions themselves, but that they aren't transparent. ORMs are a frequent offender here: a good abstraction wouldn't allow you to perform a thousand database queries by accident just by looping over a list. You could still model a list of database-backed persistent objects as a list, but any operation that hits the database should be an explicit fetch, not an implicit one.
- renox 6y agoHaving an array 'view' with a pointer to the end of the array seems much more simple to manage that having to manage a sentinel value. Less accidentally quadratic algorithms, this way!
- Leherenn 6y agoAre manual loops, the kind that that can be replaced by iterators, really "hideously error-prone"? Don't get me wrong, I'll take the iterator approach every day, because the index is simply complexity I don't need, but I've never seen issues with the basic for(int i...). Off by one errors tend to happen when you start doing index arithmetic, and iterator are not going to help you there.
- chousuke 6y agobasic loops certainly don't go wrong all that often, but once you get to more difficult requirements, the iterator abstraction really helps. Maybe you need to iterate over two differently sized datastructures in lockstep, or over a complex nested structure, or accumulate and filter the values, or load the data into a temporary buffer that gets flushed and reused once it fills up, or maybe your data source is infinite, or all of the above. These are cases where using iterators is significantly safer and notably, more composable.
- enriquto 6y ago> or that manual loops are "simpler" than proper iterator abstractions, LOL at "proper iterator abstractions" to replace loops. You will take loops from my cold, dead hands!
- scoutt 6y ago> it's just byte buffers! At the end of the day, all things are.