6 ms·
> For array types, C2 introduces a new operator, namely elemsof(). This returns the number of elements in an array sigh PHP - count Python - len C++ - .size
by nadams 11y ago
> For array types, C2 introduces a new operator, namely elemsof(). This returns the number of elements in an array
sigh
PHP - count
Python - len
C++ - .size (vector)
C - macro or stored
C# - .Length
- PythonicAlpha 11y agoYes, "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.
- tagrun 11y agoGo's len() sounds nicer to me.
- deleted 11y ago[deleted]
- arihant 11y agoThis is why C is sort of unassuming in its "sizeof arr / sizeof *arr" pattern. Whenever you write a new type, just write a sizing function for it using sizeof. I like that Go is taking a similar route, except that one just implements the signature.
- mastax 11y agoC# is even more annoying because there is .Length .Count .Count() and .LongCount() and different types implement different ones.