• Yoddel_Hickory@piefed.ca
      link
      fedilink
      English
      arrow-up
      2
      arrow-down
      1
      ·
      edit-2
      4 hours ago

      Type is more important? So if the first argument of a function is minAge, which is an int, the important part is that it is an int? Just feed it any int?

      No, the important part is the meaning, what the variable actually is, if you use a compiled language the compiler will handle types for you anyway. You’ll get a error if you feed it a string, or an water heater object, no surprises.

      Leave the machine work to the machine (compiler in this case), and concentrate on the real work, which is the meaning here.

    • Armand1@lemmy.world
      link
      fedilink
      English
      arrow-up
      12
      ·
      edit-2
      8 hours ago

      As other users have said, we aren’t compilers.

      Types are important for type safety, so you don’t access properties that don’t exist, can use polymorphism etc. However, having worked in both duck-typing and hard typing languages, I believe the most important part of a type is it’s name.

      Classes are are arbitrary constructs we create to help us understand and manage code. They are inherently organisational structures.

      That may sound like an argument FOR putting the name of the class first. “If I know it’s a ConnectionCredentialsQuery, I don’t need to know it’s name, the use-case is evident!” Classes often get reused though, like a CartesianPoint. You may create several instances of them. Which of the name and type below are more indicative of use?

      CartesianPoint PlayerPosition; 
      

      Types are, to some extent, implementation detail. The name tells you what the variable is for, which is more important.

      Another point: You will always need to name variables well, because after declaration, whenever you see a variable, you will only see its name. You want to be able to fully understand what you are looking at without having to mouse over or go back to the declaration of a variable.

      Additionally, many typed languages will allow you to use a syntax to altogether avoid declaring the type of a variable if derived from somewhere else.

      var result = a + b;
      
      var customer = new Customer();
      

      Given that the type can be inferred, and therefore specifying it explicitly is optional, why make it the first thing you see? That means you need to move your eye back and forth when looking for the names of things. Which of these two are better for legibility:

      var result = a + b;
      CartesianCoordinate playerPosition;
      
      const result = a + b;
      let playerPosition: CartesianCoordinate; 
      

      Finally, you say that types are more important because they are important to the compiler, but compilers don’t care about the order of these definitions. Compilers exist to allow us to write easier to read code. They exist to convert high level languages to low level byte code. They exist to enable more readable code.

      Thank you for coming to my TED talk.

      • ∟⊔⊤∦∣≶@lemmy.nz
        link
        fedilink
        English
        arrow-up
        9
        arrow-down
        1
        ·
        11 hours ago

        Maybe, but i speak English that follows adjective - noun pattern. So I’m already conditioned to type - name

        • Victor@lemmy.world
          link
          fedilink
          English
          arrow-up
          4
          arrow-down
          1
          ·
          10 hours ago

          My language does that, as well as English in which I am fluent. I still find type-first to be impractical.

          Also when you write the code, you are usually looking to create a variable, so maybe you type “var” or “const”, right, then you have a contextual name in mind, maybe salary. Then you can make a decision, which type it should be. Maybe “whole dollars”? “Dollars in a decimal number”? Or it could be a complex type in other contexts.

          That’s how I prefer to write code. 👍

          Maybe it makes more sense to someone who knows more than one language as well, e.g. languages that use a noun-adjective structure, like French, or Farsi. I don’t know. But for me it’s not about language, it’s about practicality. Findability and writability, if those can be considered words, lol.

          • Takapapatapaka@tarte.nuage-libre.fr
            link
            fedilink
            Français
            arrow-up
            1
            ·
            10 hours ago

            My main language is french, and yet i prefer the type-name order. Maybe its because i first learned C, but i guess its also because it goes from general to particular, whereas name-type feels like going backward (being detailed with name, then vague with type, then more detailed with value assignment). Anyway, i guess you’re right, it’s probably not a lot about language.

            • Victor@lemmy.world
              link
              fedilink
              English
              arrow-up
              1
              ·
              10 hours ago

              Exactly, first language (spoken or programming) doesn’t seem to play a role. It’s more about the mental model. 👍

    • Joelk111@lemmy.world
      link
      fedilink
      English
      arrow-up
      9
      ·
      11 hours ago

      Maybe this comes from a non-typed language perspective… As someone who learned in Java, I do not like it because yeah, type is way more important. If someone was coming from Python, I can see why they might think this…

      • it_depends_man@lemmy.world
        link
        fedilink
        English
        arrow-up
        3
        ·
        9 hours ago

        I only use python and I don’t understand why someone might think that. The order in python’s type hints is wrong too.

      • faintwhenfree@lemmus.org
        link
        fedilink
        English
        arrow-up
        4
        ·
        10 hours ago

        I learned C++ first, have been using python for the last decade almost daily for various one off tasks. I like python, but if I had to build something that will be used even hundred of thousand times, I wouldn’t do it in python.

        Anyway point being, despite me using for decades, I still yearn for C++.

        • MangoCats@feddit.it
          link
          fedilink
          English
          arrow-up
          1
          ·
          5 hours ago

          I tried to use C++ in 1991 but the Borland Turbo C++ compiler was too buggy, so we used C instead. By 1996 C++ was “ready for primetime” on IBM-compatible PCs (yes, they still called them that, sometimes in 1996) and I switched - for 30 years.

          I just spent 10 days building a proof of concept in Python, all the “common wisdom” says that was the fast way to get it done. Now that the prototype is done and the (initial) user feedback is addressed, I’m running a port to something better for lightweight, performant, easy deployment… sadly, C++ isn’t even on the radar for potential targets - top 3 candidates were Go, Rust and C#. I can’t abide the C# ecosystem, and Rust is just a little too rigid and immature for my tastes, so here we Go… anticipated to take 50% longer to port from Python than the Python took to develop in the first place… we shall see…

      • Victor@lemmy.world
        link
        fedilink
        English
        arrow-up
        5
        arrow-down
        1
        ·
        11 hours ago

        I learned Java first. I think type should come second as well, like in TypeScript et al.

        If you’re ever looking for the variable manually for some reason, by searching with your eyes, it’s easier to find it by searching in the first character column.

        Otherwise, if you ever need to see the type of something, which… should be obvious from the context in quality code, your LSP should just be able to tell you directly, by some mechanism (hover with mouse, or some keyboard action).

      • Valmond@lemmy.dbzer0.com
        link
        fedilink
        English
        arrow-up
        2
        ·
        10 hours ago

        Script languages are quick and dirty (but slow), I hate it when they try to shoehorn every high level concept into them.

      • andallthat@lemmy.world
        link
        fedilink
        English
        arrow-up
        7
        ·
        11 hours ago

        I think that’s so type inference can work by just omitting the type, instead of having to use “var” or “auto” in front of the variable name

        • chrash0@lemmy.world
          link
          fedilink
          English
          arrow-up
          1
          ·
          1 hour ago

          not precisely. Rust has let mut and Kotlin has val; ie the member layout and the mutability are treated differently, since those languages have mutability rules.

          this is a circular argument anyway. the language designers could have figured out a way to do type inference like, eg, Java, but, again, explicitly chose not to.