• Thorry84@feddit.nl
    link
    fedilink
    arrow-up
    334
    arrow-down
    1
    ·
    11 months ago

    Yes the compiler/interpreter can figure it out on the fly, that’s what we mean by untyped languages. And as stated both have their merits and their faults.

    Elon doesn’t know what the words mean and just chimes in with his AI future BS.

    • Blue_Morpho@lemmy.world
      link
      fedilink
      arrow-up
      96
      ·
      11 months ago

      And as stated both have their merits and their faults.

      Yes! Just because a compiler could guess the type doesn’t mean it should. Elon didn’t understand the meme at all.

      • AVincentInSpace@pawb.social
        link
        fedilink
        English
        arrow-up
        3
        arrow-down
        1
        ·
        11 months ago

        why would you not want it to? what circumstance, other than an integer not given an explicit type, could it guess wrong?

          • floofloof@lemmy.ca
            link
            fedilink
            English
            arrow-up
            10
            arrow-down
            4
            ·
            11 months ago

            I almost upvoted but for that last sentence. Code block scopes are most intuitive, and JavaScript has become a better language since it gained them.

            • Blue_Morpho@lemmy.world
              link
              fedilink
              arrow-up
              3
              arrow-down
              2
              ·
              edit-2
              11 months ago

              Yeah I use it too. But when I have to read somebody’s code or my own from a while ago, I prefer everything labeled at the top. That way I can read the top, jump anywhere, and know what is going on without looking at any other lines.

              It’s a preference that can be argued like dynamic typing.

              • floofloof@lemmy.ca
                link
                fedilink
                English
                arrow-up
                3
                arrow-down
                1
                ·
                edit-2
                11 months ago

                I guess you could make a rule of declaring your variables at the top of their scope, be it a class, a function or a code block. That would give clarity without needlessly expanding any scopes.

          • AVincentInSpace@pawb.social
            link
            fedilink
            English
            arrow-up
            5
            ·
            11 months ago

            I’m not talking about dynamic vs static though. I’m talking about static typing with or without compiler type inference a la Rust or C++'s auto

            (note that Java making generic parameters optional does not count since that is, in fact, dynamic typing)

          • Lime66@lemmy.world
            link
            fedilink
            arrow-up
            2
            ·
            11 months ago

            I also prefer static typing but I like it when it is implemented like kotlin where type inference is still great, I think dart also works like that

        • RepulsiveDog4415@feddit.de
          link
          fedilink
          arrow-up
          4
          ·
          11 months ago

          Well, if there is nof fixed (explicit or implicit) type it’s imposible for the compiler to optimise your code. Also imho programming with typed languages is way easier because your IDE can recognize function argumentd before you compile/run. I tried python and found it baffling how anyone can get any work done with it :D

          • AVincentInSpace@pawb.social
            link
            fedilink
            English
            arrow-up
            2
            ·
            11 months ago

            I used Python almost exclusively before I learned Rust and inevitably became a full time Rust bro, and the answer is “slowly and with a lot of crashes” :P

            anyway, as I said in another comment, I’m not talking about static vs dynamic typing, I’m talking about static typing with vs without a compiler that can do type inference. C++'s auto will default to floats if you don’t tell it the type of a number which is pretty brain dead, and there are scenarios where it’s helpful to write out a type that could be inferred for readability/guaranteed correctness’s sake, but apart from that I can’t think why having most of your types be implicit would be bad

    • janAkali@lemmy.one
      link
      fedilink
      English
      arrow-up
      66
      arrow-down
      4
      ·
      edit-2
      11 months ago

      Yes the compiler/interpreter can figure it out on the fly, that’s what we mean by untyped languages.

      Are there untyped languages? You probably meant ‘dynamically typed languages’.

      But even statically typed languages can figure out most types for you from the context - it’s called ‘type inference’.

      • nul@programming.dev
        link
        fedilink
        arrow-up
        91
        ·
        11 months ago

        Most of my code is untyped. First I type it, then I realize it’s all wrong and use backspace to untype it.

      • Traister101@lemmy.today
        link
        fedilink
        arrow-up
        16
        arrow-down
        1
        ·
        11 months ago

        Assembly probably? So low level you kinda just play with bits. That’s all I can think of for an untyped language. Everything else I’m aware of is dynamically or statically typed

        • Chobbes@lemmy.world
          link
          fedilink
          arrow-up
          9
          ·
          11 months ago

          I kind of feel like “untyped” is a term that doesn’t really have a proper definition right now. As far as I can tell when people say “untyped” they usually mean it as a synonym for whatever they consider “dynamically typed” to mean (which also seems to vary a bit from person to person, haha). Sometimes people say assembly is untyped exactly for this reason, but you could also consider it to have one type “bits” and all of the operations just do things on bits (although, arguably different sized registers have different types). Similarly, people sometimes consider “dynamically typed languages” to just be “unityped” (maybe monotyped is more easily distinguished from untyped, haha) languages at their core, and if you squint you can just think of the dynamic type checks as a kind of pattern matching on a giant sum type.

          In some sense values always have types because you could always classify them into types externally, and you could even consider a value to be a member of multiple types (often programming languages with type systems don’t allow this and force unique types for every value). Because you could always classify values under a type it feels kind of weird to refer to languages as being “untyped”, but it’s also kind of weird to refer to a language as “typed” when there isn’t really any meaningful typing information and there’s no type system checking the “types” of values. Types sort of always exist, but also sort of only exist when you actually make the distinctions and have something that you call a “type system”… In some sense the distinction between static and dynamic typing is sort of an arbitrary implementation detail too (though, of course, it has impacts on the experience of programming, and the language design makes a bit of a difference in terms of what’s decidable :) (and obviously the type system can determine what programs you consider to be “valid”)… But you can absolutely have a mix of static type checking and dynamic typing, for instance… It’s all a little more wishy washy than people tend to think in my opinion).

          • Traister101@lemmy.today
            link
            fedilink
            arrow-up
            4
            arrow-down
            1
            ·
            11 months ago

            Well like asembly has “int types” and “float types” as there’s specific instructions for those operations but those instructions don’t actually care if the bits are for a float or an int. Types in a language are used to restrict the valid operations. In a statically typed language you cannot call cat.bark() or dog.meow() because the property’s of the type, what things you can do with it are known before the program runs. In a dynamically typed language such as Python cat.bark() might or might not be valid so it has to check at runtime for a method throwing an error if it doesn’t exist.

            Static/Dynamic typing is a difference of when. Java has static typing but you can also just pass raw Objects around and cast when needed. It even throws a runtime exception similar to how Python or JavaScript would fail. However Java is of course ultimately statically typed everything just shares a common parent class and has types at runtime which allows for some some psudo dynamic behavior

            • Chobbes@lemmy.world
              link
              fedilink
              arrow-up
              3
              ·
              11 months ago

              There’s operations that treat bits like floats and operations that treat them like various kinds of ints, but the meaning of bits is in the eye of the beholder. There’s even good examples of mixing and matching integer and floating point operations to clever effect, like with the infamous fast inverse square root. I feel like people often think mathematical objects mean something beyond what they are, when often math is kind of just math and it is what it is (if that makes sense… it’s kind of like anthropomorphizing mathematical objects and viewing them through a specific lens, as opposed to just seeing them as the set of axioms that they are). That’s kind of how I feel with this stuff. You can treat the bits however you want and it’s not like integer operations and bitwise operations have no meaning on supposedly floating point values, they do something (and mixing these different types of operations can even do useful things!), it just might not be the normal arithmetic operations you expect when you interpret the number as a float (and enjoy your accidental NaNs or whatever :P).

              The difference of static and dynamic typing being when you perform the type checking is partially why I consider it to be a somewhat arbitrary distinction for a language (obviously decidable static type checking is limited, though), and projects like typescript have shown that you can successfully bolt on a static type system onto a dynamic language to provide type checking on specific parts of a program just fine. But obviously this changes what you consider to be a valid program at compile time, though maybe not what you consider to be a valid program overall if you consider programs with dynamic type errors to be invalid too (which there’s certainly precedence for… C programs are arguably only real C programs when they’re well-defined, but detecting UB is undecidable).

      • AVincentInSpace@pawb.social
        link
        fedilink
        English
        arrow-up
        3
        ·
        11 months ago

        I guess “untyped” could mean “weakly typed”, like how shell and DOS batch are, where everything is a string until you say “hey I want to do math on this” at which point the interpreter turns it into a number, does math on the number, and then turns it back into a string before saving it back to the variable

      • Thorry84@feddit.nl
        link
        fedilink
        arrow-up
        5
        arrow-down
        4
        ·
        11 months ago

        Well that would depend on the definition and what you exactly mean by untyped.

        The untyped part is usually referring to the way the programmer interacts with the language, for example not setting a type for variables and parameters. But then there is the question of is the programmer ever allowed to explicitly set the type. And further more, if the programmer explicitly set the type, does this mean the type can’t change at a later point? And another question could be, can the programmer check or enforce what type a variable or parameter is? And the question, if there is only one type of data in the language, would that be a typed or untyped language? But I would consider these to be details and all fall under the untyped umbrella, with untyped just meaning not-typed.

        Then there’s the question of the technical implementation of the language. Defining a language is one thing, actually having it run on a real system is another. Usually technical systems at some point require explicit types. Something somewhere needs instructions on how to handle the data and this usually leads to some kind of typing instructions being added along with the data. But depending on how many abstraction layers there are, this can soon become a very pedantic discussion. I feel what matters is the design, definition and intend of a language. The actual technical implementation isn’t what matters in my opinion.

        I feel like there are so many programming languages and technical systems at this point, every variation and exception exists. And if you can think of one that doesn’t exist, expect a follow up comment of somebody pointing out it does exist after all, or them having started a project to make it exist in the near future.

        • Poutinetown@lemmy.ca
          link
          fedilink
          arrow-up
          2
          ·
          11 months ago

          Would you say OCaml or any ml family language would be untyped since they have type inference?

          • Thorry84@feddit.nl
            link
            fedilink
            arrow-up
            4
            ·
            11 months ago

            From what I know about those I would consider those to be typed languages. Even if the programmer doesn’t explicitly assign the types, he needs to be aware of them and take into account what type something will be. I am familiar with F# and it’s strongly typed for example.

      • cucumber_sandwich@lemmy.world
        link
        fedilink
        arrow-up
        36
        ·
        11 months ago

        Programming term. Variables in programming languages can hold different types of data, such as whole numbers, floating point numbers or strings of characters (“text”). Untyped languages figure out on the fly what can and cannot be done to the content of a variable, while typed languages strictly keep track of the type of content (not the value) to catch bugs and improve performance, for example.

      • RagingRobot@lemmy.world
        link
        fedilink
        arrow-up
        8
        ·
        edit-2
        11 months ago

        By typed they mean declairing a type for your variables.

        In some languages, variables needs to be told what kind of data they can hold. That’s it’s type. For instance a number without decimals would be an integer type. While text might be a string type or a list of character types.

        Other languages don’t require types and sometimes don’t even support them. They will just infer the type from the data that’s in the variable.

        If you see Elon Musk please explain this to him.

      • jtk@lemmy.sdf.org
        link
        fedilink
        English
        arrow-up
        1
        ·
        11 months ago

        Might be able to call assembly untyped. Everything beyond that I think would be called either statically or dynamically typed, maybe weakly typed?

    • hemmes@lemmy.world
      link
      fedilink
      English
      arrow-up
      9
      arrow-down
      1
      ·
      11 months ago

      Even in untyped can’t you explicitly set your type either with declarations or wrapping the value in quotes for a string or something?