News for hackers. Stuff that matters.
Re:From zero to 10M lines of Kotlin by mariusmg on Tuesday October 25, 2022 @10:07AM (#33330637)
>I dont really get why I would leave out the explicit types in the source code

One my pet peeves, shit like this sucks :

var f = MyStupidMethod();

Re:From zero to 10M lines of Kotlin by MajimasEyepatch on Tuesday October 25, 2022 @10:30AM (#33330928)
In practice, the return type is often obvious. You can write:

  val foo = new MyReallyLongUglyFactoryClass()
instead of:

  MyReallyLongUglyFactoryClass foo = new MyReallyLongUglyFactoryClass()
And you never _have_ to use type inference. If you have a method where the return type isn't as obvious, you can always annotate it explicitly:

  val foo: Int = doSomeThing()
Do people exercise judgement about when to make the type explicit? Eh, depends on the team. But if you combine type inference with established conventions in a particular codebase (e.g. I/O calls always return IO[Foo]), you will rarely be left wondering what the type of something is.
Re:From zero to 10M lines of Kotlin by jeremyjh on Tuesday October 25, 2022 @10:27AM (#33330890)
Yes but that isn't real code. If you see something like:

> var conn = openDatabaseConnection();

Are you actually confused about what conn represents? Does it matter what the exact type is, if you already know what it is and what you can do with it?

Re:From zero to 10M lines of Kotlin by kevmo314 on Tuesday October 25, 2022 @10:38AM (#33331037)
Yeah it does, I don't really know what I can do with it. A type annotation would be useful to search for.
Re:From zero to 10M lines of Kotlin by wiseowise on Tuesday October 25, 2022 @01:18PM (#33333463)
Maybe you need to start using IDE, instead of programming in nano.
Re:From zero to 10M lines of Kotlin by kevmo314 on Tuesday October 25, 2022 @02:16PM (#33334228)
Maybe you need to go work for GitHub to fix their code search references, instead of trying to act superior to random people on the internet.
Re:From zero to 10M lines of Kotlin by wiseowise on Tuesday October 25, 2022 @03:24PM (#33335004)
I'm using Intellij, VSCode and Code Search for searching, why would I use GitHub for it?
Re:From zero to 10M lines of Kotlin by LinXitoW on Tuesday October 25, 2022 @06:41PM (#33337153)
I mean, you could just search for the method called, if you're REAAALLLLLYYY averse to using any IDE or editor of the last 10 years. Which would be an odd choice to base language decisions on.
Re:From zero to 10M lines of Kotlin by dalyons on Tuesday October 25, 2022 @10:16AM (#33330748)
Why? The compiler knows what the type is, the ide can tell you the type if you need to know - it’s redundant for you to have to type it out.
Re:From zero to 10M lines of Kotlin by ivanche on Tuesday October 25, 2022 @10:42AM (#33331095)
Now do the code review in GitHub. Ooops!
Re:From zero to 10M lines of Kotlin by wiseowise on Tuesday October 25, 2022 @01:15PM (#33333428)
I do code review on GitLab all the time, what’s the issue?
Re:From zero to 10M lines of Kotlin by ivanche on Thursday October 27, 2022 @07:05AM (#33355837)
No compiler there so the compiler can't tell you the type. No IDE there so the IDE can't tell you the type. You're at the mercy of colleague(s) not to write code like var request = service.call() or, worse, var b = getResult().
Re:From zero to 10M lines of Kotlin by RhodesianHunter on Tuesday October 25, 2022 @02:51PM (#33334649)
Never have this issue. I'm not being hyperbolic either. I review Kotlin PRs every day and am never lost for context on a type.
Re:From zero to 10M lines of Kotlin by Iwan-Zotow on Tuesday October 25, 2022 @10:21AM (#33330821)
nonsense

this line has zero readability

you're not writing code for compilers, you're writing code for people

Re:From zero to 10M lines of Kotlin by toqy on Tuesday October 25, 2022 @10:28AM (#33330900)
I prefer inferred types when available. Then an IDE and compiler can get together to provide further details when needed. Honestly f: MyStupidInterface = myStupidMethod(); doesn't tell me much more.
Re:From zero to 10M lines of Kotlin by bottled_poe on Tuesday October 25, 2022 @10:36AM (#33331017)
The era of strong vs weak typing debate has passed. Adopt strong typing, like a professional, or fade into the 90s web. Harsh but fair.
Re:From zero to 10M lines of Kotlin by dalyons on Tuesday October 25, 2022 @10:58AM (#33331409)
practically all modern strongly typed languages are adopting or already had type inference from day one, allowing you to do things like var. They give up nothing in terms of strong typing to do so. Forcing people to write manual boilerplate does not equal professional, what a strange take.
Re:From zero to 10M lines of Kotlin by bottled_poe on Tuesday October 25, 2022 @11:03AM (#33331506)
The engineering trade-offs are paid somewhere, better in an objective space than a subjective one.
Re:From zero to 10M lines of Kotlin by dalyons on Tuesday October 25, 2022 @11:45AM (#33332144)
i dont know what you mean by this?

Fundamentally, this is a story of technology getting better (type inference in compilers) so humans can do less work. We're not pushing the work to some other human place. We're not losing anything in safety, and we're gaining in readability, boilerplate and expressiveness. Its progress!

Re:From zero to 10M lines of Kotlin by 3836293648 on Tuesday October 25, 2022 @11:32AM (#33331971)
Noone is arguing for weak typing. They're arguing for type inference. They're not even slightly the same thing
Re:From zero to 10M lines of Kotlin by jeremyjh on Tuesday October 25, 2022 @11:50AM (#33332228)
The era of not knowing the difference between static typing, strong typing, and type inference is past. I'm the sort of professional who likes to learn computer science.
Re:From zero to 10M lines of Kotlin by dalyons on Tuesday October 25, 2022 @11:03AM (#33331487)
> you're not writing code for compilers, you're writing code for people

i agree, thats why i don't want to clutter my code with annotations designed for the compiler, not humans. Type inference is a _good_ thing for readability.

Re:From zero to 10M lines of Kotlin by Larrikin on Tuesday October 25, 2022 @11:52AM (#33332256)
You can just the type hints in the IDE for bad code like the above example. But glancing through my code, that is never an issue in practice because code reviews should have caught the poorly named variable and method.

Since the actual size of the code base isn't an issue in the modern world, I personally like that the Kotlin ecosystem discourages the use of esoteric names and non obvious abbreviations. Once you write and read enough of it you stop making poor choices.

Re:From zero to 10M lines of Kotlin by wiseowise on Tuesday October 25, 2022 @01:16PM (#33333440)
Nonsense is doing compiler work yourself, even bigger nonsense is duplicating for zero reason.
Re:From zero to 10M lines of Kotlin by mcv on Tuesday October 25, 2022 @01:59PM (#33334048)
> One my pet peeves, shit like this sucks :

> var f = MyStupidMethod();

Yeh, but so does:

  List<MyWeirdoFooClass> myWeirdoFoos = new ArrayList<MyWeirdoFooClass>();
Sometimes it's clear what it is. Sometimes you don't really care. Sometimes you do. You can still make it explicit when you need it to be explicit.