News for hackers. Stuff that matters.
Re:How I Program in 2024 by fendy3002 on Sunday August 04, 2024 @11:30PM (#41157948)
have you worked with java or C#? both are where types sometimes become a burden.

No, you cannot just do something like this:

``` return { data, message: "OK" }; ```

you need to declare a class or struct that match the definition. There's mapper and builder everywhere. Adding / deleting 1 column from a datatype can force you to make changes in 5 places due to mapper / builder.

Re:How I Program in 2024 by kmoser on Monday August 05, 2024 @12:16AM (#41158151)
The flip side of this "burden" is that it prevents you from returning an arbitrary data structure that is not expected by the caller and may cause errors further down the call stack if you return the wrong type. The whole point of static typing in the first place is to eliminate this kind of footgun.
Re:How I Program in 2024 by fendy3002 on Monday August 05, 2024 @02:23AM (#41158582)
have you tried typescript? the code above will make the function declaration become like this:

function foo (): {data: MyCustomObject, message: string}

so foo().data and foo().message is a valid object, while foo().bar will throw build error

Re:How I Program in 2024 by seer on Sunday August 04, 2024 @11:42PM (#41158004)
As a matter of fact - no I haven’t. My experience with types is TypeScript, Elixir and a bit of Scala.

I always try to have “clojure style” types where I don’t try to be too prescriptive - don’t lock things down if you don’t need to, just the minimum possible types to make sure the code I’m writing is correct, and nothing more - Rich Hicky’s talks on Clojure’s Spec was an eye opener.

I have been told by some java devs though that it is a matter of style - while unconditional it is possible to write java code with much less boilerplate if one uses newer language features and actually tries to hold the cruft at bay. Is that true?

Re:How I Program in 2024 by fendy3002 on Sunday August 04, 2024 @11:46PM (#41158026)
idk, haven't use newer java or C# after 2014-ish, though I think I've read C# has support some dynamic typing, never explore that. Never touch Elixir and Scala too so cannot comment on that.

TS though, the type declaration is amazing with it's union, optional and intersection type!

Re:How I Program in 2024 by behnamoh on Sunday August 04, 2024 @11:59PM (#41158084)
> My experience with types is TypeScript, Elixir and a bit of Scala.

Dude, Elixir only recently introduced some sort of a type system...

Re:How I Program in 2024 by ianleeclark on Monday August 05, 2024 @02:50AM (#41158685)
Elixir has had dialyzer + type hints for years
Re:How I Program in 2024 by seer on Monday August 05, 2024 @03:49AM (#41158984)
While not part of the compiler, the dialyzer’s types are quite nice, even if sometimes it is a bit clunky - I’ve noticed that most of the time when I thought it was “wrong” it actually wasn’t and had picked up on some bug / misunderstanding in my code, though error messages could have been better
Re:How I Program in 2024 by AdieuToLogic on Sunday August 04, 2024 @11:54PM (#41158069)
> have you worked with java or C#? both are where types sometimes become a burden.

> No, you cannot just do something like this: > ``` return { data, message: "OK" }; ```

Yes, in Java you can:

  return new Object() {
    String message = "OK";
    Object data = itsValue;
    };
There are many reasons to dislike Java and it is nowhere near my programming language of choice. The specific semantic deficiency you chose happens to be an invalid one.
Re:How I Program in 2024 by dasyatidprime on Monday August 05, 2024 @03:37AM (#41158929)
And how does the caller extract those fields?
Re:How I Program in 2024 by AdieuToLogic on Saturday August 10, 2024 @01:18AM (#41207503)
> And how does the caller extract those fields?

The same way one would when returning an anonymous map in JavaScript - via reflection and the assumption of what was returned.

While JavaScript makes the use of reflection less burdensome, it has the same collaboration fragility as a Java version. Just with less ceremony.

Re:How I Program in 2024 by phito on Monday August 05, 2024 @02:22AM (#41158575)
You can do that in C# with dynamic types. But realistically it's almost never used because it's kinda dirty.

To each their own I guess, I've never felt burdened by types but I feel like I'm programming in the dark when using a non typed language.

Re:How I Program in 2024 by qball on Monday August 05, 2024 @02:24AM (#41158588)
Yes you can. C# has had anonymous types since language version 3.0, released nearly 20 years ago; everyone who has used .Select() at the end of a LINQ query has used this.