News for hackers. Stuff that matters.
Re:Go and Java: Rethinking Type Safety for the Pragmatic Age by coin on Tuesday November 26, 2024 @04:42PM (#42250366)
Go is too minimalist in my opinion. It’s like time warping back to 2005. You want enums, nope. You want functional constructs (map, filter), nope. You want string array contains, nope. It can feel very limiting coming from newer languages designed in the last 10 years.
Re:Go and Java: Rethinking Type Safety for the Pragmatic Age by desumeku on Tuesday November 26, 2024 @05:02PM (#42250551)
Functional programming is not "newer", it is as old as Lisp, which dates back to the 60s. The people who made Go simply decided that the language did not need those features.
Re:Go and Java: Rethinking Type Safety for the Pragmatic Age by RadiozRadioz on Tuesday November 26, 2024 @05:12PM (#42250632)
So instead we have 10 different libraries and 100 different custom implementations to do those things in Go. Compared to almost every other major language where you can do functional stuff (and everything else the Go developers decided we didn't need) natively:

    Java: Arrays.stream(nums).map(n -> n * n).toArray();
    Kotlin: nums.map { it * it }
    Python: list(map(lambda x: x*2, nums))
    C#: nums.Select(n => n * n).ToArray();
    Ruby: nums.map { |n| n*2 }
    Rust: nums.iter().map(|&n| n * n).collect();
    Perl: map { $_ * $_ } @nums;
Re:Go and Java: Rethinking Type Safety for the Pragmatic Age by desumeku on Tuesday November 26, 2024 @05:15PM (#42250671)
Rob Pike has talked before[1] on this exact subject, about how all languages are merging into one giant PL-theory sludge where every camp is adding and stealing features from one another, and that one of purposes of Go was to avoid following in this same direction.

[1]: https://youtu.be/_cmqniwQz3c?t=34

Re:Go and Java: Rethinking Type Safety for the Pragmatic Age by RadiozRadioz on Tuesday November 26, 2024 @05:28PM (#42250787)
Fair enough. I agree with the sentiment that we need diversity in languages.

Personally, when I'm solving a problem, I like to reach for the pre-established universally understood pattern that's built into my language. Rather than using a language that doesn't have any of those things and requires me to create my own, worse, implementation that's unique to my program (or use a random 3rd-party module of dubious quality for something basic).

Re:Go and Java: Rethinking Type Safety for the Pragmatic Age by coin on Tuesday November 26, 2024 @05:54PM (#42251030)
Agree. Removing useful features in the name of diversity seems silly.

> requires me to create my own

Yes, how many string contains methods are there out there, as the result of everyone having to write their own.

Re:Go and Java: Rethinking Type Safety for the Pragmatic Age by johnnyjeans on Tuesday November 26, 2024 @05:28PM (#42250794)
You could just use a for-statement, you know. I feel like there's a reactionary avoidance to iteration to the point that it doesn't really make sense.

I feel like we've jumped out of the frying pan of the 90s' OOP craze, directly into the fire of doing the same cargo cult behavior with functional programming. Always avoid loops, always use higher-order functions. It just makes sense. If you are not provided with the shotgun spread of higher-order functions out of the box, be frustrated.

I vaguely recall reactions to Haskell in the late 90s where vitriol was spewed over the lack of inheritance and classes.

Re:Go and Java: Rethinking Type Safety for the Pragmatic Age by coin on Tuesday November 26, 2024 @05:52PM (#42251007)
Loops are just clutter. I’d rather concentrate on the filter and transform and not be bothered with the raw mechanics of looping, creating an intermediate array and appending to it. Not to mention that some languages returns a lazy evaluated view of the original storage.
Re:Go and Java: Rethinking Type Safety for the Pragmatic Age by RadiozRadioz on Tuesday November 26, 2024 @05:40PM (#42250915)
In my particular example, these were of course deliberately simple snippets to illustrate the point. The power comes in chaining these things, .map.filter.reduce... . Using iteration, you end up writing a lot of boilerplate that is much harder to parallelise, and extremely difficult to lazily evaluate. Without these constructs, to express "the concept of filtering & reducing an array", the reader of your program needs to read how you implemented those things, in addition to what you're using them for. You can do that stuff yourself in goroutines, but there is no contest to having native support for these extremely common operations.
Re:Go and Java: Rethinking Type Safety for the Pragmatic Age by henryjcee on Tuesday November 26, 2024 @04:50PM (#42250438)
Strong, strong agree on this. That plus the verbosity really adds to the activation energy of getting things done. I reckon I end up writing (and having to read) 5x the lines of code for the same result that then ends up being less type safe and lacking null safety. I guess that's the price you pay for simplicity.
Re:Go and Java: Rethinking Type Safety for the Pragmatic Age by kgeist on Tuesday November 26, 2024 @05:03PM (#42250556)
>You want string array contains, nope

Go now has slices.Contains

Re:Go and Java: Rethinking Type Safety for the Pragmatic Age by thegeekpirate on Wednesday November 27, 2024 @10:33AM (#42256831)
> You want enums, nope.

It has enums, and if you want exhaustive checking, use golangci-lint (as every good gopher should be already, considering the language ensured tooling would be easy to write) https://golangci-lint.run/usage/linters/#exhaustive

> You want functional constructs (map, filter), nope.

There are libraries for map/filter (just make sure you use one with deforestation)

> You want string array contains, nope.

https://pkg.go.dev/slices#Contains