Hacker News new | comments | show | ask | jobs | submit login

> 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




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.


It seems to have been chosen so there is some parallelism between sizeof and elemsof.


It also makes the fact that you are referring to a size/length/count of elements, and possibly not bytes, very explicit.


To 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 ...


That'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.


Then 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 ...


I'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.


I 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.


> I on my part (in spite using C myself) think that typing code is not that problem, but typing the right code.

What do you think of the auto keyword in C++? I've personally never found typing out the types to be a problem.


Hi, I must admit, that I am not totally up-to-date when it comes to C++, since I am not hopping on the newest standards as soon as they are there. And I am not actively programming in C++ currently.

But I don't think, that "auto" was specified to reduce typing. I see it more as a possibility to follow the "DRY" principle (don't repeat yourself).

There might be cases, where for example the return types of functions might change and you don't want to change every caller.

Templates are of course an other example, because the return types of templates oftentimes are depending of the input types. You of course can use those template declaration stuff, but it is very ugly and oftentimes clumsy.

I also found a nice example, where it really can help to make things more easy to read, here:

http://stackoverflow.com/questions/252671/auto-c-c/12573433#...

I think, the real usages are rare, that is also the reason, it was specified rather late.


Why not numberOfEnemiesOnSamePlatform()?


I 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.


MATLAB uses numel()


Go's len() sounds nicer to me.


This 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.


C# is even more annoying because there is .Length .Count .Count() and .LongCount() and different types implement different ones.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: