8 ms·
Yes, "elemsof" is not only another new name, but in my opinion, it is also a name that does not disclose itself easily. Good naming in programming is an art.
by PythonicAlpha 11y ago
Yes, "elemsof" is not only another new name, but in my opinion, it is also a name that does not disclose itself easily.
Good naming in programming is an art.
- kmill 11y agoIt seems to have been chosen so there is some parallelism between sizeof and elemsof.
- bitshiffed 11y agoIt also makes the fact that you are referring to a size/length/count of elements, and possibly not bytes, very explicit.
- PythonicAlpha 11y agoTo me it does not disclose that easily. The parallelism between "sizeof" and "elemsof" seems to me very constructed. "size" and "elements" are not similar words. To be logical at all, the name should be "numelemsof" or "countelemsof" ... but I guess, those names are already to long for C purists ...
- Serow225 11y agoMATLAB uses numel()
- andresmanz 11y agoThat's true all too often. Meanwhile, though, I prefer long and expressive names. You can easily find functions like getNumberOfEnemiesOnSamePlatform() in my C and C++ code. I don't think it's very hard to understand what that function does. With a few special exceptions, I haven't written any comments for almost two years and nobody ever complained.
- omaranto 11y agoWhy not numberOfEnemiesOnSamePlatform()?
- andresmanz 11y agoI couldn't get used to that form yet. getNumberOfEnemiesOnSamePlatform() is imperative, while numberOfEnemiesOnSamePlatform() is not. I think it's because I'm not a native English speaker, but the get version sounds like 'give me that value' to me, which would make sense. Usually, my function names are imperative (often with the exception of event handling functions) and that feels more natural to me. I'll do some research on the topic, though. There's a presentation where someone explains it, but I couldn't follow last time.
- PythonicAlpha 11y agoThen I would not call you "C purist". The "C purists" I knew, refused to much typing. It also was the reason they refused other languages for example such with "tiresome long" words like "begin" and "end". I on my part (in spite using C myself) think that typing code is not that problem, but typing the right code. And -- at least when you are not alone programming -- every code line is read 10 or more times more often than it is written. So, to be clear and understandable is much more valuable to me, than come away with less strokes ...
- JoeAltmaier 11y agoI've been plagued by supposed 'purists' all my career. What they are, really, is bad at typing. They won't refactor a crap method because it would take them too long to type it all The best investment in my career I ever made is, typing class in high school. It has separated me from the crowd at every job. Its more important that so many other irrelevant 'purist' ideals.
- PythonicAlpha 11y agoI never had a formal typing class and I guess I am still not that fast in typing, but with the years I learnt my keyboard (even in the US and the German variant) and for my opinion I am typing fast enough now, since I have to think sometimes between the strokes, still. But when I look back at my career, I never had the feeling, to be to slow in typing even for Module II -- a language, that would never ever get the approval of the "C purists". Doing refactoring, I use a simple trick myself -- I do much copy and paste ;) ... and delete (!) the copied stuff afterwards. I think, as a programmer, it is a good property to be lazy -- but you should merely use it for code reuse instead for avoiding typing. Oh, I forgot: I use vim, a typing avoidance editor. You can avoid lot of keystrokes or mouse moves with that editor. But not to avoid real content.
- tagrun 11y agoGo's len() sounds nicer to me.