News for hackers. Stuff that matters.
Re:Things I Was Wrong About: Types by withinboredom on Sunday September 27, 2020 @11:09AM (#24607179)
I work on the big data side of Automattic, so I tend to work with PHP, Typescript/JavaScript, Python, and Scala, but I also work with C# for fun. When you work with and without types often, you realize that it doesn't matter. Types are great for expressing constraints on the code, but you can do the same thing with conventions in non-typed code.

IMHO, type-less provides some resiliency. If you write code for a "string" anything that satisfies "stringiness" will still run just fine. This lets you build types that "trick" the code you're calling, which can be useful sometimes. I think I've abused this capability less than 3 times, but more than once. Mostly it allowed me to significantly change behavior without rewriting huge chunks of core code. However, these were all proof of concepts. Don't get it twisted, working with no types is pretty annoying sometimes.

Types, on the other hand, are great for most things, but I do find they get in the way sometimes. It's annoying when you look at the code you're calling and see that it only uses `.x` on a type you pass it, but you have to completely build a type just to create a `.x` on the type you pass in. I once found a NullPointer bug in HDFS with a static type (very strange) and had to work around it doing exactly this. Anyway, I think I'd like Go's approach to interfaces.

Re:Things I Was Wrong About: Types by musingsole on Sunday September 27, 2020 @11:15AM (#24607245)
Those who argue strongly for one method over the other are likely to not understand the one they're against. Which sucks, because if you do know both, there's rarely a reason to have strong feelings one way or another. So, once again the naive but vocal voices get all the decision power.

/Too many arguments at work are over dogma and I have to spend a lot of my time reminding people that there are options. That's all. There are options. Your kneejerk response to a problem might be fine -- might be right -- but there are always options.

Re:Things I Was Wrong About: Types by loup-vaillant on Sunday September 27, 2020 @11:43AM (#24607465)
I was never sure what to think of dynamic typing, until I tried to implement a fairly simple Earley parsing algorithm in Lua. The thing was 50 lines, and I was lost. I only managed to get runtime errors such as "you can't add functions, you can't apply a number, this reference is null…

That's when I understood where TDD came from: dynamically typed languages require so many tests to work reliably that we better write those tests first so we're not tempted to omit them.

Anyway, I redid the whole thing in OCaml, and this time got lots of compile time errors. Which I could correct, and once the compiler was happy, well… my program was basically correct.

---

I still don't rule out that other people's brains are wired fundamentally differently. I don't expect it, it would surprise me, but I honestly don't know. What I do know is that dynamic typing is not for me. I'll suffer through it to get other advantages (Python's comprehensive library for instance), but that's about it. Dynamic typing and I are otherwise done.

Re:Things I Was Wrong About: Types by withinboredom on Sunday September 27, 2020 @11:55AM (#24607574)
> The thing was 50 lines, and I was lost.

The key to writing type-less code is making it so simple that you could cry. Avoid being clever at all costs. However, it's almost the exact opposite when you have a nice compiler checking everything, you can be mighty clever and know that it will work.

I'm lucky in that we can solve a problem in a myriad of languages, depending on if it needs to be "realtime", or can be precomputed. There are some types of problems I'd rather solve in Scala, and others, Python or PHP. It just depends.

Re:Things I Was Wrong About: Types by loup-vaillant on Sunday September 27, 2020 @06:39PM (#24610757)
> The key to writing type-less code is making it so simple that you could cry.

I can't help but interpret this as "the key to writing type-less code is choosing problems so simple that you could cry". In other words, dynamic typing doesn't scale.

When I have a very simple problem to solve, sure, I won't mind dynamic typing. For anything worth more than an hour of coding however, I'll definitely reach for more reliable tools.

Re:Things I Was Wrong About: Types by musingsole on Thursday October 01, 2020 @02:01PM (#24654140)
You can look at it that way, or you could look at it like comparing RISC vs. CISC architectures. RISC would seemingly be too simple to accomplish everything CISC does but that's the beauty of being Turing complete.
Re:Things I Was Wrong About: Types by withinboredom on Sunday September 27, 2020 @11:30AM (#24607364)
To expand on that, the options also have trade-offs. They can both be just as right or wrong, and the trade-offs be the deciding factor.
Re:Things I Was Wrong About: Types by rswail on Sunday September 27, 2020 @11:13AM (#24607219)
Using interfaces/traits/protocols don't preclude strong typing.

If you write code for a type that "has" stringiness, as expressed by a trait, then anyone can build a variant of their types that expresses that trait.

Re:Things I Was Wrong About: Types by withinboredom on Sunday September 27, 2020 @11:39AM (#24607430)
Yeah, for sure. That's certainly possible, but I rarely see people build for it, at least when it comes to value types like strings, ints, etc.

One other thing that I DO like about type-less, is the ability to introspect, for example, in PHP:

``` foreach ((array) $my_class as $property => $value): ```

vs. a bunch of boilerplate and making sure types match up in most strongly-typed languages.

Re:Things I Was Wrong About: Types by mceldeen on Sunday September 27, 2020 @11:45AM (#24607481)
> IMHO, type-less provides some resiliency. If you write code for a "string" anything that satisfies "stringiness" will still run just fine.

Things like that are actually possible to do in a light weight way in FP languages and many of them are part of the stdlib. (PureScript happens to be my favorite example.) Many times it brings back the same feelings I had working in Ruby (which I also happen to love), but with the added confidence of a strong type system.

Re:Things I Was Wrong About: Types by withinboredom on Sunday September 27, 2020 @12:02PM (#24607640)
Scala is the closest I've gotten to FP at work. I'd love to play with Haskell/F#/etc in a professional setting, it just hasn't come up. Yet.
Re:Things I Was Wrong About: Types by mceldeen on Sunday September 27, 2020 @11:02PM (#24612558)
Haskell family languages are something unique. I’ve never worked with Scala so I can’t say.