77
you are viewing a single comment's thread
view the rest of the comments
[-] relative_iterator@sh.itjust.works 10 points 1 year ago

I don’t understand how types could be time consuming.

[-] nous@programming.dev 7 points 1 year ago

Some things are very easy to do in loosly typed languages - just as letting a function take a string or int, and then parsing that string into an int if a string was passed in. In a loosly typed language you can just call something like if typeof(input) but in a strongly typed language you often need a lot more boiler plate and extra wrapper types to say the function can only take an int or string - for instance in rust you might need to wrap them in a enum first or some how create a trait and implement that for each types.

This is quite a bit of extra upfront cost some of the time that really rubs people that are used to loosly typed languages the wrong way. So they think it is slow to work with types. But what they never seem to count is the countless hours you save knowing that when you read a value from something and pass it to a function that wants only an int, that the value is an int and you dont end up getting 2 + "2" = "22" and other suprising bugs in your program. Which results in less time debugging and writing tests for weird cases the compiler does not allow.

But all that extra time if often not counted as that is dissociated from the original problem at hand. And they are already used to this cost - people often notice a new cost, but don't notice a possibly bigger saving else where.

[-] wasted@programming.dev 4 points 1 year ago

I never understood this argument. If your function is supposed to take an int, then parse your string before calling it?

[-] nous@programming.dev 3 points 1 year ago

There are reasons you might want to, such as you are constructing something that has a few different ways to create it. Like maybe a date, can parse it from a string, pass in each bit as a separate argument, take in a Unix timestamp.

A lot of languages encourage this with constructors as you can often only have one.

IMO it is far better to just have different functions for each type you want to build something from like how it is done in rust.

But when you come from a language that encourages the opposite it can seem clunky to have to define separate functions for each. And it can take a while to accept the different way of working.

[-] JackbyDev@programming.dev 4 points 1 year ago

I agree, but I imagine dynamic type fans would say they don't understand why explicitly stating types can be helpful.

Optional typing is pretty useful, especially if the tooling is such that it catches most issues. I use Python's optional typing quite a bit, and my general approach is to add types if the function is intended to be reused or if it took more than three seconds to figure out what it does. We also use Typescript, and typing isn't necessary there either.

If your type system is too strict, it can be really annoying to work with and make simple things take longer. If it's too loose, you'll introduce stupid bugs.

[-] basskitten@programming.dev 1 points 1 year ago

If your type system is too strict, it can be really annoying to work with and make simple things take longer.

Swift has entered the chat.

Yeah I think it’s a misunderstanding. There’s no way they aren’t encountering issues from dynamic types.

[-] bitcrafter@lemmy.sdf.org 2 points 1 year ago

It can be nice not to have to worry about types when you are doing exploratory programming. For example, I once started by writing a function that did a computation and then returned another function constructed from the result of that computation, and then realized that I'd actually like to attach some metadata to that function. In Python, that is super-easy: you just add a new attribute to the object and you're done. At some point I wanted to tag it with an attribute that was itself a function, and that was easy as well. Eventually I got to the point where I was tagging it with a zillion functions and realized that I was being silly and replaced it with a proper class with methods. If I'd known in advance that this is where I was going to end up then I would have started with the class, but it was only after messing around that I got a solid notion of what the shape of the thing I was constructing should be, and it helped that I was able to mess around with things in arbitrary ways until I figured out what I really wanted without the language getting in my way at intermediate points.

Just to be clear, I am not saying that this is the only or best way to program, just that there are situations where having this level of flexibility available in the language can be incredibly freeing.

And don't get me wrong, I also love types for two reasons. First, because they let you create a machine-checked specification of what your code is doing, and the more powerful the type system, the better you can do at capturing important invariants in the types. Second, because powerful type systems enable their own kind of exploratory programming where instead of experimenting with code until it does what you want you instead experiment with the types until they express how you want your program to behave, after which writing the implementation is often very straightforward because it is so heavily constrained by the types (and the compiler will tell you when you screwed up).

[-] eluvatar@programming.dev 1 points 1 year ago

From some of my own conversations with people they don't find it useful as a solo dev because they have to read the docs for dependencies even with types, and they only ever have to deal with their own code which they know we'll enough that they see types as a waste of time.

this post was submitted on 06 Jul 2023
77 points (98.7% liked)

Programming

17314 readers
334 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 1 year ago
MODERATORS