Personally I love oranges but cant stand orange juice.

    • invertedspear@lemmy.zip
      link
      fedilink
      English
      arrow-up
      5
      ·
      7 hours ago

      In programming you declare variables. To keep it simple let’s say there are only 2 types, numbers and words.

      Now 1 is obviously a number, and ‘word’ is obviously a word. If I ask you to divide 100 by ‘word’ you’d have to tell me that’s not possible.

      Now what if a say divide 100 by the “word” ‘10’? Well I’m a strongly typed programming language, you’d have to tell me “well, because you defined it with the single quotes, that’s actually a word so you can’t do math on it.” In a loosely typed language you’d be like “yeah I get that ‘10’ meant the number 10 so I’ll do the math.

      This creates amusing weirdness in loosely typed languages, especially when they use math operators to represent word actions. For instance JavaScript is infamously loosely typed and uses the + sign to join words together so if I say ‘Java’ + ‘Script’, I get back ‘JavaScript’. So all the following are true in JavaScript:

      1+1=2 1-1=0 ‘1’+1=11 because the ‘1’ makes it think you want to join words and it converts the second number 1 to a word ‘11’-1=10 because there’s no word operation applied to the minus sign, so it converted the word ‘11’ to a number

      There’s lots of other tomfoolery, but I’m trying to keep the explanation simple. But any mixing of words and numbers in a strongly typed language would just give you an error.

      I’m with the top reply of this thread, you don’t need strong typing if you understand what the code does.

      • jimmux@programming.dev
        link
        fedilink
        arrow-up
        3
        ·
        5 hours ago

        I think strong/static typing with inference is the sweet spot. Complex types can change, so it helps to at least have your boundaries well defined. Within the scope of a function, if you need explicit typing on everything then your function might be getting too complex.

    • chunes@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      7 hours ago

      It’s a feature of a programming language that usually, but not always, requires you to declare what sort of data everything is (this is a number, this is text, this is a person object I made, etc.). Then you are required to run your program through a program called a compiler before you are allowed to run it, to (among other things) make sure that everything is what you said it was.

      Basically, it requires you to be extra pedantic, but some say it catches common errors. But imo these are the sort of errors that only come up because you have tons of people working on one project.