Navigation

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

    Is it me, or are if statements messy?

    Comments & Feedback
    13
    17
    802
    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.
    • Aceba1
      Aceba1 last edited by

      An elseif keyphrase (or elif) could simplify the process as well

      1 Reply Last reply Reply Quote 1
      • A
        Alexander last edited by

        I like it the way it is.... but if you added an elseif would you still need an additional endif? and would it break the original coding, because, that would be a boring day of editing broken code...

        1 Reply Last reply Reply Quote 0
        • Jongjungbu
          Jongjungbu F last edited by Jongjungbu

          My preference with IF statements is is more like:

          if ( a >5 ) then bDone = 0 else bDone = a endif

          I like less lines hahaha

          1 Reply Last reply Reply Quote 0
          • Hitomi
            Hitomi F last edited by Hitomi

            The point of an elseif keyword is that it would be used in a statement such as if condition then statement elseif condition 2 statement elseif condition 3 statement endif. That would make it one long statement that doesn't need pairing off for each condition. That means nested statements aren't necessary as often. That's the way lua and some versions of basic do it. I'd like to see it in FUZE, but it's not necessary, just helpful. In C like languages like Java and Javascript you don't need another syntax for it because a single statement doesn't need an extra set of braces, so you can use the two separate words else if and it will still balance out and be a valid statement.

            1 Reply Last reply Reply Quote 2
            • Jonboy
              Jonboy Fuze Team last edited by

              I can't see IF statements changing but we will be adding SWITCH for sure.

              Discostew 1 Reply Last reply Reply Quote 2
              • Discostew
                Discostew F @Jonboy last edited by

                @Jonboy Switches in my Switch? Switchception!

                1 Reply Last reply Reply Quote 1
                • Jonboy
                  Jonboy Fuze Team last edited by

                  Just wait till the XBOX version!

                  Discostew 1 Reply Last reply Reply Quote 1
                  • Discostew
                    Discostew F @Jonboy last edited by

                    @Jonboy said in Is it me, or are if statements messy?:

                    Just wait till the XBOX version!

                    Wait, wha?

                    1 Reply Last reply Reply Quote 0
                    • _
                      _JKDOS F @Nisse5 last edited by

                      @Nisse5 said in Is it me, or are if statements messy?:

                      @_JKDOS FWIW, there's no need for using "else" in the example, since none of these are in conflict (unless "abc" is changed within the "if" block). But if you want it structured like a case statement, you can do:

                      That is really neat.

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

                        I also feel like if statements have room for improvement. I've expressed some ideas below. Even though it might not 100% align with the ideas of the Fuze team, I hope my chain of thought is useful anyway:

                        inline if statements IIF
                        If the arguments to a function call are conditional, I currently do not have many options. Basically I see two patterns:

                        pattern 1:

                           value = 1
                           if condition then
                              value = 2
                           endif
                           stuff(value)
                        

                        pattern 2:

                           if condition then
                              stuff(2)
                           else
                              stuff(1)
                           endif
                        

                        I would however like to use the inline if statement pattern (from other languages: stuff(condition ? 2 : 1)).
                        In F4NS I'd think a syntax like this would work:

                           stuff(IIF condition THEN 2 ELSE 1 ENDIIF)
                        

                        IIF standing for 'inline if', and ending with ENDIIF in stead of ENDIF.

                        Fundamentally the difference is that an IIF must always decide on a statement that returns a value. Opposed to IF that executes conditionally.

                        keyword to prevent nesting ELSEIF

                        ELSEIF could easily be a keyword, that helps reduce the amount of nesting for correlated if statements (keeping the cognitive load of the code lower). This way only one ENDIF keyword would be needed for correlated conditions. It would be possible to follow up IF with multiple ELSEIF's and even one optional ELSE after those (ELSEIF would not be possible after ELSE).

                        For example:

                           string value
                           IF i < 0 THEN
                               value = "negative"
                           ELSEIF i > 0 THEN
                               value = "positive"
                           ELSE
                               value = "neutral"
                           ENDIF // using ELSEIF would not require an additional endif
                           stuff(value)
                        

                        combining the two keywords
                        The following code could be reduced if we were allowed to combine those two keywords. Currently in F4NS you would write something like this:

                           string value
                           if i < 0 then
                               value = "negative"
                           else if i > 0 
                               then 
                                   value = "positive"
                               else
                                   value = "neutral"
                               endif
                           endif
                           stuff(value)
                        

                        A possible option would be to introduce ELSEIIF (as an inline ELSEIF):

                           stuff( IIF i < 0 THEN "negative" ELSEIIF i > 0 THEN "positive" ELSE "neutral" ENDIIF)
                        

                        Or otherwise IIF could be nested like so:

                           stuff(
                              IIF i < 0 THEN
                                 "negative" 
                              ELSE IIF i > 0 
                                 THEN 
                                    "positive" 
                                 ELSE 
                                    "neutral" 
                                 ENDIIF 
                              ENDIIF
                           )
                        

                        Type agnostic short circuiting

                        I guess you could name the following pattern "type agnostic short circuiting". It can be addictive, and this would work in JavaScript, but for F4NS this would probably be a bad idea:

                           stuff( (i < 0 && "negative") || ( i > 0 && "positive") || "neutral")
                        

                        I know F4NS has the AND and OR keyword, but in my opinion it's more intuitive if those keywords would always resolve in a boolean value, where as && and || would then be able to resolve to other types (as shown in the example above).

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