Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple APILearn More
hitko30724yVarying syntax aside, fixed data structures like strings & arrays are generally implemented as a continuous block of memory with certain LENGTH. Other data structures, like sets and dictionaries, are commonly implemented as linked cells (either flat, or in a tree-like structure). For those types, you usually have multiple sparse blocks of memory, so you have either COUNT nodes, or a tree with certain SIZE.
Mitiko64294yArray has . Length and List has .Count
But they both have a .Count(predicate<object>) method
It's weird but you get used to it
Don't forgot lua's # operator.
My favourite in this way is trimming white spaces from string (trim vs strip) - I never get it right on first try...
TRex10524ywhere's is the super-upvote button. anyone?
In C, sizeof and len mean different things. Sizeof gives you the size of an array in bytes, possible padding included. The idiomatic usage of length however refers to the maximum element count, and that's only the same as sizeof for arrays of byte type.
If you want to get the length of an array regardless of its underlying type, the expression is even weirder:
len = sizeof(arr)/sizeof(arr);
But here comes the next fun part, when you hand over an array to a function, the function only sees a pointer without array length information, so you have to supply it as separate function parameter.
The final fun thing is that you can still use sizeof(arr_ptr)/sizeof(arr_ptr) in the function, but it will divide the pointer width of the architecture by the size of the underlying type, which is usually nonsense.
Root835764yI never remember random functions.
karma112464yWrong image, we all agreed this was the new gender selection component!!!
Can we all agree that .__len__() is the worst one
jak64520254yEach time i switch language XD
How language creators choose the function to get the size of an array..
I mean, the life could be more simple, this is just an example.
tag in a tag