Built-in Function Switch
364
Views
10
Comments
New
Service Studio

Create a Built-in Function Switch, under the Miscellaneous tab. It makes it easier for developers to understand the intended behavior than having several if's chained. It may cause fewer errors, since it is not necessary to check the same variable/condition several times.

I think that will promote bad behaviour. An assign shouldn't have multiple ifs chain. OutSystems is a mixed graphic/tex based programing language, so the best practive would be to use the graphic part as much as possible. Otherwise, what's the point, right? :)

I can give you several examples where you have no other way of doing it. Look at this example in the 'Building a Patient Self-Service Portal' Guided Path:

Wouldn't it be more intuitive for developers to have one switch instead of all these ifs?


Well, that's true, I will give you that, although, you could always create an action, set the function property as true and do all that logic in a graphic switch. I would say it's way easier to maintain than have logic in text boxes, even if it's only 4 ifs, but that's my opinion. I don't like to have logic there because I find it harder to understand later.

Cheers

If you think about it, then you wouldn't need the Built-in function if() either. We could simply make a function with an If node inside, just like you suggested. If there was a need to create such a function, then why isn't valid to suggest to create a Switch function?

Best regards

In my opinion that if function also promote bad behaviour and I would live better without it, it makes it so much harder to read the code because you have to stop paying attention to the graphic flow and go read the logic inside a text box, and people overuse it and worst, use multiple ifs like you mention. 

I don't think the switch is a bad idea, at least it would make those ifs more readable. But I don't think it should be the way because instead of promoting good practices, with that, people would continue to add logic to text boxes, which I don't think it's ok.

Cheers

I also don't like the nested if(if(if... in expressions, it is hard to read and maintain, to much code 

Changed the category to
Service Studio

I have used nested ifs on the table cell when checking the condition. I hope we will get a solution for this. It would be great if we have a built-in Switch case.

Merged this idea with 'Switch Statement in Expressions' (created on 28 Mar 2023 20:51:45 by DerAstrit)

As an OutSystems developer, I would like to request a switch statement in expressions. Currently, when we have multiple if statements in expressions, it can become cluttered and difficult to read. A switch statement would make the code more organized and easier to understand. 

For example, we could use a switch statement like this:

switch (x) { 
case 1: // code block break; 
case 2: // code block break; 
case 3: // code block break; 


I believe that the addition of a switch statement in expressions would be a great improvement to the OutSystems platform, and it would greatly benefit all developers who use the platform.