August 9, 20169 yr Hi Guys, Stumbled onto this (old) article: http://www.databuzz.com.au/an-approach-to-filemaker-server-side-script-debugging uses a case with a single condition: Set Variable [ $serverLogSQL; Case ( $EnableLoggingSQL ; BE_FileMakerSQL ("DELETE FROM ServerLog") ) ] My question, what would be the benefit of using case as opposed to an if statement? Both would look and act pretty similar. Is there a performance difference? Edited August 9, 20169 yr by OlgerDiekstra amending
August 9, 20169 yr No, most of it is personal preference. I often use Case() myself where an If() would do, especially when I'm not sure if I'll need to add conditions as I go along.
August 9, 20169 yr When I specifically KNOW that only two options are possible, such as male/female, yes/no, active/inactive etc, I prefer to use If() so it is explicitly clear. Otherwise, like Wim, I use Case() so it is simpler to add additional options (in different sequence) later. BTW, this question comes up from time to time. I recall asking the exact same question and exact same subject line when I was new to FileMaker! :-)
August 9, 20169 yr I got in the habit of using Case for the reason Wim mentioned -- you might need to add more conditions later -- but also because in the past, an If calculation always required a "result two," even if that would be a pair of empty quotes. In that scenario, the Case calculation was "cleaner" since it didn't require the result two. E.g.: Case( 1; "hello" ) ... vs. ... If( 1; "hello"; "" ) But several versions back, the If calculation was upgraded, and no longer requires a result two to be valid. So it really is mostly a personal preference. Just please don't use nested Ifs, use Case for that!
August 9, 20169 yr For years, I have used Case() exclusively, because it does everything that If() does and more. In fact, I viewed If() as a legacy function, provided only for backward compatibility. Recently, however, under the influence of other programming languages, I have decided that the better practice is to use Case() only when there are multiple tests. This makes it easier for anyone reading the formula. I've never understood the "I may need to add more tests later" thing; how long does it take to double-click "If" and type "Case" over it? I am not aware of any differences in performance.
Create an account or sign in to comment