“I consider that a man’s brain originally is like a little empty attic, and you have to stock it with such furniture as you choose. A fool takes in all the lumber of every sort that he comes across, so that the knowledge which might be useful to him gets crowded out, or at best is jumbled up with a lot of other things, so that he has a difficulty in laying his hands upon it. Now the skillful workman is very careful indeed as to what he takes into his brain-attic. He will have nothing but the tools which may help him in doing his work, but of these he has a large assortment, and all in the most perfect order. It is a mistake to think that that little room has elastic walls and can distend to any extent. Depend upon it there comes a time when for every addition of knowledge you forget something that you knew before. It is of the highest importance, therefore, not to have useless facts elbowing out the useful ones.”
What is the benefit of having this page embedded into your memory?
While there are legitimate reasons for languages to differ in approach, style and, consequently, their syntax – what is the reason why we can’t have length of array taken the same way in all or most of programming languages?
Groovy decided to be all original and went with .size() method. JavaScript obviously could not pass on opportunities for interesting decisions and .length is a property. Kotlin – merge of the two previously mentioned, .size. Lua, geez, is there anything about this language that does not make you want to kill yourself – made #array the way to take length.
I’m not even going to comment this.
PHP! count()
is the way.
Python. len()
, because 2 letters make a difference.
Ruby – .length
, Rust – .len()
, Scala – .length
Guess what – "${#array[@]}"
.
Why do I have to store all of this rubbish in my head, taking space that might be used for something actually valuable and meaningful? Why do we limit the ability of collaboration between users of different languages? Why are we repeating errors made millennia ago, when life itself not-so-gently reminds us that usage of lingua franca, common system of measurement, common system of counting time, common system of geographical representation are vastly superior to localised solutions.
I mean, there is a word, length. That perfectly describes what is it we are after.
Length makes sense as an object property\field\whatever. It’s a characteristic of a thing.
Count is a verb which makes sense as an instruction for action to be performed on something – so a method taking something countable.
There’s nothing to discuss here. It’s a dead simple case having direct analogy in real world actions, and still there’s gazillion of different ways of doing same (incredibly simple and mundane) thing. Is it really surprising to find more complex concepts and actions represented by even bigger zoo of senseless naming conventions?
New languages are not really taking all this as an input to reduce the amount of rubbish in developer’s head. And I really wish someone would. Even more so, I’d wish existing languages would have future versions of the language change their own original solutions into something standard. Mathematics has done this quite some time ago. It’s about time computer science followed suit.