OlgerDiekstra Posted August 9, 2016 Posted August 9, 2016 (edited) 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, 2016 by OlgerDiekstra amending
Wim Decorte Posted August 9, 2016 Posted August 9, 2016 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.
LaRetta Posted August 9, 2016 Posted August 9, 2016 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! :-) 1
Fitch Posted August 9, 2016 Posted August 9, 2016 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!
comment Posted August 9, 2016 Posted August 9, 2016 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. 2
Recommended Posts
This topic is 3084 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now