5 ms·
"Kotlin changed the extends keyword into the : operator, which is already used to separate variable name from its type. Back to C++ syntax? For me it’s confusin
by V-2 8y ago
"Kotlin changed the extends keyword into the : operator, which is already used to separate variable name from its type. Back to C++ syntax? For me it’s confusing."
Not only C++; C# also. It's not very hard to confuse the author, is it :) I understand it's different from Java he's used to, but that doesn't mean one can hold every such difference against Kotlin. Not being Java isn't in and of itself a fault of a language.
Why is ":" problematic exactly? It's more concise. It's true that this gives ":" more than one meaning, but it's so clearly context-dependent I can't really see how it could cause confusion when coding. An example would help.
(Ruby uses "<" to denote class inheritance - by some miracle Ruby devs manage to get over the fact that "<" is also an arithmetic operator :) )
- hellofunk 8y agoAnd that’s not even how C++ uses the colon!
- Sir_Substance 8y ago>Why is ":" problematic exactly? It's more concise. Anyone, including non-java programmers, can make an educated guess at what the "extends" keyword does to a java class. The colon operator is contextless. Unless someone tells you or you've coded in c++/c#, you can't know for sure what it means without googling it. Here's a case in point, my biggest bugbear with the nim documentation. When you first see nim code, you're gonna see the '@' operator pretty much immediately. You're going to wonder what it does, and google "nim @ operator". You'll then remember that googling symbols doesn't work very well, and google "nim at-symbol operator". Sooner or later, you'll find your way here: https://nim-lang.org/docs/manual.html#lexical-analysis-operators https://nim-lang.org/docs/manual.html#lexical-analysis-opera... The nim documentation helpfully says "Yes, the @ symbol is an operator". So what does the @ operator do? It's a mystery, go fuck yourself, errr I mean figure it out for yourself! If you ignore the mystery and move on with your learning you'll come back to it via the key word "seq" within about 10 minutes, but there's no easy way to search for it if you don't know that, and by the way what a frivolous waste of time. Shorthand symbols are worth having, but they should be used only in cases where the coding speed benefit outweighs the readability loss. If you had to write "extends" in kotlin instead of use a colon, how often would you be doing it? If it's more infrequent than once every 2 minutes I would argue that "extends" is better because it's in natural language, and thus easier on average for new kotlin developers to understand /regardless of background/.
- V-2 8y ago"If you had to write "extends" in kotlin instead of use a colon, how often would you be doing it?" Certainly more often than you'll need someone to tell you what ":" in a class declaration does ;) I see your point, I just don't think this language trait deserves to rank as "confusing" for a professional programmer. While we're at it, Kotlin, unlike Java, provides explicit "constructor" and "init" keywords. So if it loses points for the lack of "extends", why doesn't Java for not having these? Nim's manual doesn't seem helpful indeed (they acknowledge it openly in the beginning), but I feel this is sort of beyond the point. Kotlin's docs are very clear and exhaustive. Case in point - as we discussed inheritance declarations - https://kotlinlang.org/docs/reference/classes.html https://kotlinlang.org/docs/reference/classes.html
- Sir_Substance 8y ago>So if it loses points for the lack of "extends", why doesn't Java for not having these? No one said it didn't :) In general, I personally prefer my languages explicit for a variety of reasons. There's a balance for sure, and one can go too far the other way. For example, I find Rust to be a shade too unwieldy for my optimum preferences, although I would overlook that to gain the safety benefits if I had the right use case.
- jhall1468 8y ago> The colon operator is contextless It has a type after. Always. Even assuming that's not enough for it to click, that Google search took all of 3 seconds and you are now typing ":" over "extends" thousands upon thousands of times. If you honestly thing one of those takes more time than the other, you haven't really thought this through. This is a silly argument.
- Sir_Substance 8y ago>and you are now typing ":" over "extends" thousands upon thousands of times That's blatant hyperbole, and also a worthless argument. How many times have you typed "int"? Should we replace it with a symbol? Maybe go back to space-cadet keyboards[1]? J is a language built around symbols for maximum programming speed. It's not an esolang, it's real and usable, and recently updated. Here's a very simple J function: result=: {&((65 97+/~i.2 13) |.@[} i.256)&.(a.&i.) Very efficient, minimum keystrokes. Can you tell me what it does? Fundamentally, programming languages are for people, not computers. Otherwise, we'd all be coding in assembly. Keystrokes are /not/ the expensive or dangerous part of programming, we shouldn't be optimising our languages to reduce them. Optimising languages to reduce miscomprehension is the future, that's where expensive developer time and business risk is concentrated. Preferring to type a colon instead of the word "extends" is, bluntly, the sort of thing you solve with a custom autohotkeys file. In any case, it's a minimal gain either way with the : operator, that kind of decision won't make or break any language. But this is the internet and if we're going to argue over something so trivial, I'm going to argue that on the most nitpicky level, "extends" is clearly a better choince than ":". [1] Space-cadet keyboards are really cool
- Roboprog 8y agoOK, so I’m used to : from doing Pascal back in the 80s, but anyway. Read the colon as “is a”, and it makes sense. “counter is a number” “DogClass is a (special) MammalClass”. Not seeing a problem there, but again, I have no particular love for curly brace languages. And I would MUCH rather see the type expression spewage AFTER the symbol name - especially given Java 5 generic declarations mixed with Java 8 lambda declarations (yuck!).
- AlphaSite 8y ago`var` helps a little.
- bdavisx 8y agoActually, the colon is consistent here: `val x: Integer` means x isA integer; `class Dog(): Animal()` means Dog isA animal. They mean the same thing within their respective contexts.