Feature request stack switch cases like other languages

Propose new features and changes
hastegag
Posts: 3
Joined: 03 May 2017, 20:14

Feature request stack switch cases like other languages

14 Aug 2020, 18:17

I appreciate every last thing the AHK devs have done, and the addition of the switch statement is fantastic, but I would like to be able to stack switch cases like you can in other languages, rather than have them comma delimited. In brief, I wouldn't mind seeing the following equivalent if it was easy, but I see why that could be a problem as it just looks for the 'case' keyword followed by something and ending in a ':'

Code: Select all

Case "AcceptAllFormatChanges","AcceptAllandStopT","InsertNotesInText":

Code: Select all

Case "AcceptAllFormatChanges":
Case "AcceptAllandStopT":
Case "InsertNotesInText":
the reasoning being, you can access the switched variable in multiple 'cases' in fewer lines, or at least without having a really long single lines here and there, in this situation, I was doing this beneath where I was looking to stack various cases

Code: Select all

Switch params[1]
;...
ComObjActive("Word.Application").Run("!" . params[1])
and I have also used the switch case in message monitors, which with a streamdeck or similar are very powerful, but you have to have so many cases and a lot of times, as you add them it is nice to be able to use line position editing to move them around. Just by way of example and not every editor has this feature, but you can move entire lines up and down in notepad++ which is quite handy for Case statements, especially as you may realize along the way they need to be in a different place or sort order for clarity and consistency.

Humbly requested!
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Feature request stack switch cases like other languages

14 Aug 2020, 18:37

Code: Select all

Case "AcceptAllFormatChanges"
   , "AcceptAllandStopT"
   , "InsertNotesInText":
hastegag
Posts: 3
Joined: 03 May 2017, 20:14

Re: Feature request stack switch cases like other languages

14 Aug 2020, 18:49

thanks, that is a great suggestion, and I will implement it, but you still need to auto add the "Case " part on the front of the line, factoring in indentation if you are moving things around to different logic, but I guess it isn't too much, or just find some means of auto-adding it in the IDE (like Npps macro recorder) or with AHK (although ingesting the current indentation sounds like a lot of effort given the circumstance).

Thanks for the tip!
lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: Feature request stack switch cases like other languages

14 Aug 2020, 19:49

I specifically chose not to permit implicit fall-through, because it is a cause of errors in other languages. Even if it were permitted only for empty cases, that would cause a problem when a case body happens to be commented out or not yet implemented (and isn't intended to execute the next case). There is only superficial advantage, if any (I would argue there is none), to stacking lines with Case versus just listing all of the possible values for that case as shown above.

I have no idea what you mean by "auto add the Case part", and don't see what the problem is with indentation.

I don't think "ingesting" indentation would be any effort, since it has no substance. I'm sure you meant some other word. :lol:
hastegag
Posts: 3
Joined: 03 May 2017, 20:14

Re: Feature request stack switch cases like other languages

14 Aug 2020, 20:02

lexikos wrote:
14 Aug 2020, 19:49
I specifically chose not to ... Even if it were permitted only for empty cases, that would cause a problem when a case body happens to be commented out or not yet implemented (and isn't intended to execute the next case).
Understood, this makes perfect sense. Thanks Lexikos!

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 52 guests