Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    So types don't matter?

    Advanced
    3
    5
    409
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • W
      WhiskeyJack last edited by

      I anticipated that if I don't declare a type in assignment that it would be variable as to what I assign to it

      So

      x=2
      x="foo"
      

      would be valid. However

      int x = 2
      x = "foo"
      

      being valid as well surprised me. This lack of validity also works the same way in structs. So is there any type consistency at all in Fuze as it or being planned?

      1 Reply Last reply Reply Quote 0
      • pianofire
        pianofire Fuze Team last edited by

        So currently Fuze is very loosely typed. In fact the only reason to add a type is to force local scope or in a struct declaration.

        1 Reply Last reply Reply Quote 2
        • PB____
          PB____ last edited by PB____

          Even though Fuze is loosely typed, I still think it's better to try to be consistent with your code.
          If you use int x, then use x as an int, even if it's just to avoid confusion.

          However, I do myself also use this "feature" on struct instances, when I don't know the type of a property beforehand:

          // initialization
          g = [
              .property = []
          ]
          function updateProperty()
              g.property = [
                  .newProperty = "Hello World"
              ]
          return void
          

          This is technically abusing similar flexibility, but I do hope that (or something similar) stays supported, as that provides flexibility that I like..

          When it comes to declaring variables, I personally often use a non-existing struct name var. But this is also not officially supported, so there is a non-zero chance that you need to update your code in the future if you do that. If you want to stay save for now, use the types you know in your variable declarations and stick to them when you assign values.

          There may be instances where you don't know the type. For example: c = controls(0), you might need to scope those variables to a function anyway. I would suggest to use var in these cases, but if the Fuze team eventually decides that the keyword should be bob, then there is a risk that var needs to change to bob. So I do hope future Fuze will have good find and replace mechanisms before that day D:

          EDIT: disclaimer - the above is my opinion (of a Fuze user), I have no authority at all over the choices of the Fuze team in the programming language, so keep that in mind when you make a choice in how you write your code.

          1 Reply Last reply Reply Quote 0
          • pianofire
            pianofire Fuze Team last edited by

            I can confirm that var is going to become part of the language for this purpose

            1 Reply Last reply Reply Quote 4
            • PB____
              PB____ last edited by

              That's great news, thanks! :-D

              1 Reply Last reply Reply Quote 0
              • First post
                Last post