Hacker News new | ask | show | jobs
by sixbrx 1160 days ago
R's pretty serious about it, it's why for example length("abc") returns 1, which is a head-scratcher for people coming from Python.
1 comments

Well they could read the documentation. nchar("abc") returns 3.

That's a lot easier for new programmers than len("abc"), which requires them to understand Python's string implementation. len("abc\n") returns 4 - confusing as hell for a new programmer working with a very common data analysis problem, because "length" is too generic to know it's the number of characters. nchar("abc\n") being 4 makes sense, because "\n" is a character representing a line feed. Applying the same logic, len(137) returns TypeError: object of type 'int' has no len(), when it should be 3.

At the end of the day, the programmer will always have to make an effort to learn the language they're using.