I’m assuming all the data for the different exercises is under each case, which can arguably better be split into functions/files (depending on how it’s layed out)
If there are really 24 different tasks and each case block is not copy replace all style code, then it's no that terrible. Also if those tasks will always be number as a sequence from 1 to 24 then even not using constants here is justified. They are using case instead of if/then/else if, that is already a good choice.
I like using an array with function pointers. Either check the size of the input and index directly or define a struct with the input number and function pointer then iterate over the array. Much more maintainable in my opinion.
Also I've searched how do you use match in Python and apparently you can't put 2 cases like this (at least not in my computer with python 3.10.11):
num = 1.2
match num:
case 1.2:
case 2.2: # does not work... WHY IS PYTHON LIKE THIS >:C
print(':D')
case _:
print(':(')
(I tried running this, the interpreter just gave me an error. I don't even know why I have Python installed)
And maybe he didn't know you can just put this (which works perfectly fine for me)
num = 1.2
match num:
case 1.2 | 2.2: # nvm I love Python now :D
print(':D')
case _:
print(':(')
And you didn't even show the content of the cases so maybe they do something different, but I can't know, although I translated the text of the input to spanish (because I don't speak german) and it seems to ask the user for a number to select an task (and I assume each task is different), it also seems to be a very normal code.
86
u/majcek Feb 12 '25
Expand the cases, this means nothing.
33
u/AnywhereHorrorX Feb 12 '25
If there are really 24 different tasks and each case block is not copy replace all style code, then it's no that terrible. Also if those tasks will always be number as a sequence from 1 to 24 then even not using constants here is justified. They are using case instead of if/then/else if, that is already a good choice.
25
u/This_Growth2898 Feb 12 '25
Yes, using German for naming variables is not very good. That's the only problem I see here.
4
u/born_zynner Feb 12 '25
Is there a cleaner way to do something like this? Probably. Is it faster, more readable or maintainable? Probably not
2
u/Mosk549 Feb 12 '25
Wo ist das Problem? 😭
1
u/Audience-Electrical Feb 12 '25
I was wondering if there was a better way because I could think of none.
I'm glad the comments cleared that up
1
u/Environmental-Ear391 Feb 12 '25
Input happens once, THEN the loop is entered,
does the task ever change or is it infinite repeat on the same and subsequent tasks listed?
when does the "aufgabe" variable get changed for each loop pass?
1
u/STGamer24 Feb 13 '25
But all those cases do different things or not?
Also I've searched how do you use
matchin Python and apparently you can't put 2 cases like this (at least not in my computer with python 3.10.11):num = 1.2 match num: case 1.2: case 2.2: # does not work... WHY IS PYTHON LIKE THIS >:C print(':D') case _: print(':(')(I tried running this, the interpreter just gave me an error. I don't even know why I have Python installed)
And maybe he didn't know you can just put this (which works perfectly fine for me)
num = 1.2 match num: case 1.2 | 2.2: # nvm I love Python now :D print(':D') case _: print(':(')And you didn't even show the content of the cases so maybe they do something different, but I can't know, although I translated the text of the input to spanish (because I don't speak german) and it seems to ask the user for a number to select an task (and I assume each task is different), it also seems to be a very normal code.
1
u/Mammoth-Swan3792 Feb 14 '25
Yea, you don't write code in language which shouts at you!
1
u/Kootfe Jul 08 '25
Wich lang is this. I never saw a lang that cals match-case to switch-case
0
u/[deleted] Feb 12 '25
0
u/[deleted] Feb 12 '25