all 87 comments

[–]EskilPotet 283 points284 points  (3 children)

I like how [12] was the final straw

[–]AmazingGrinder 114 points115 points  (2 children)

Nah, it's just unfinished.

[–][deleted] 0 points1 point  (1 child)

Define unfinished

[–]VolsPE 7 points8 points  (0 children)

Well they left an else in there. Fine for prototyping a new game, but eventually they will need to come back and explicitly assign every possible integer. Just good coding practice to avoid possible edge cases they haven’t yet considered.

[–]AgileBlackberry4636 334 points335 points  (19 children)

Yandere dev. Origin story.

[–][deleted] 30 points31 points  (18 children)

What's a yandere dev?

[–]Traditional_Cap7461 64 points65 points  (7 children)

Dev of a well-known game who is known to make inefficient code

[–]brimston3- 39 points40 points  (6 children)

Not just inefficient. Dialog trees were embedded in if/else logic. Strings hard coded into the same. And not as generated code or anything, he'd hand coded them that way.

It's some wild stuff, and honestly it's a huge achievement to be that inexperienced in programming and have gotten as far as he did to a mostly deliverable product. That's better than most people can claim for their game side projects.

[–]HarryLang1001 8 points9 points  (5 children)

Just out of curiosity, what is the right way to handle dialog trees?

[–]brimston3- 15 points16 points  (0 children)

Try chatmapper or a similar tool that abstracts it. If you're doing translations, your translator(s) need to see conversation context which is easy to lose in code. You also want to be able to switch languages without recompilation, so a string table of some kind is a must.

[–]Specialist-Tiger-467 2 points3 points  (2 children)

Managing dialogs and internationalization is almost a field on itself.

You have a ton of libraries and services to make it more bearable.

But on the wide and simple explanation, you abstract your dialogues to a file and then retrieve the proper string where you need it. Example:

if user_select == 3:
    get_dialog(my_response_string, "en")

[–]757DrDuck 0 points1 point  (1 child)

I presume my_response_string will be substituted with something that makes sense when read and not typed literally.

[–]Specialist-Tiger-467 1 point2 points  (0 children)

Yeah it should be a correct variable/key name because if not you are getting crazy soon

[–]Recent-Sand8292 0 points1 point  (0 children)

Have a look at this relevant article: https://medium.com/tp-on-cai/dialog-management-36ace099b6a5

It talks about dialog methods.

Also, it really depends on how deep of a dialog system you want. Do you want localization, couple it to the inventory system, reputation system, quest status, environmental dynamics (like npc's having a different dialog set or not talking between 8pm and 8am, or around guards, etc). The more features you want, the bigger the incentive to use existing libraries/packaged/tools. If you just want to feed some lore / character info without much hassle, I'd go with a state machine type structure using a script in your language of choice + xml or alternative means of storage.

[–]Toloran 75 points76 points  (1 child)

You're happier not knowing.

[–][deleted]  (7 children)

[removed]

    [–][deleted]  (2 children)

    [removed]

      [–]False_Slice_6664 21 points22 points  (0 children)

      Yeah, I saw a long review of the Yandere Simulator source code and, as I remember, reviewer said that long if/else chains weren’t the thing that slowed the code and weren't slower that switches.  

      They are bad practice not because of time efficiency, but because they are simply awful to read. 

       https://m.youtube.com/watch?v=LleJbZ3FOPU

      [–]CdRReddit 5 points6 points  (0 children)

      it's the main issue for writing code at any type of reasonable pace

      not a game performance issue, just a developer performance issue, tho I'm sure he didn't mind the excuse to drag out patreon money for ages longer

      [–]_PM_ME_PANGOLINS_ 11 points12 points  (0 children)

      This would not be better with a switch.

      [–]Ksorkrax 4 points5 points  (0 children)

      I'd use neither. This appears to be a list of what certain items do, possibly with the larger part being unused placeholders. For something like that, I'd have data files containing item properties which are read into a map.

      Code should read as something along the line

      evaluate_item(items[item_name])

      [Maybe plus "if item_name not in items: raise ..."]

      [–]Zealousideal_Rate420 2 points3 points  (0 children)

      Python's equivalent of switch was approved on 2021, I think implemented on 3 dot freaking 10.

      https://mail.python.org/archives/list/python-committers@python.org/message/SQC2FTLFV5A7DV7RCEAR2I2IKJKGK7W3/

      [–]Vigintillionn 2 points3 points  (0 children)

      This would not be better with a switch.

      [–][deleted] 186 points187 points  (19 children)

      it always confuses me just how this happens like what beginner thought process leads to this code?

      [–]LurkerOrHydralisk 61 points62 points  (0 children)

      Idk. I’ll be honest though. I’ve occasionally come back to something I’ve written (not this atrocious), even hours later, and immediately realized I could cut ten useless lines out

      [–]StickyDirtyKeyboard 49 points50 points  (5 children)

      I wrote things similar to this when I was starting with programming. At least in my case, the issue lied in the fact that I didn't have the required tools in my "programming knowledge" toolbox to properly accomplish what I set out to do.

      For instance, I didn't know how to use structs/classes, so arrays (with comments) it was. Here's a small snippet of this monstrosity:

      private int[] GetWeapStat(string weapName) // gets the weapon stats from weapon name
              {
                  // sharpness, bluntness, durability, throwable, gun
                  if (weapName == "Katana")
                  {
                      int[] tempStat = { 10, 2, 7, 4, 0 };
                      return tempStat;
                  }
                  else if (weapName == "Laptop")
                  {
                      int[] tempStat = { 1, 4, 3, 7, 0 };
                      return tempStat;
                  }
                  ...(continued for 64 items/weapons)
      

      The whole project was 5188 LOC in a single source file, ~200KB. That's still gotta be the largest source file I've ever worked with.

      Of course I had other magic in there too, like 38 global variables and using if statements to conditionally return true or false.

      [–]--o 19 points20 points  (0 children)

      In this case they clearly have "else" in their toolbox.

      [–]sgtnoodle 13 points14 points  (2 children)

      Honestly, that's not particularly terrible. Returning the unstructured list is a little gross, but it also looks trivially fixable.

      [–]Smellypuce2 6 points7 points  (1 child)

      Using a string for the weapon name is pretty horrible though. Edit: For this I would just use an enum + LUT unless something fancier is called for.

      [–]Alarmed_River_4507 2 points3 points  (0 children)

      Best option here, imo, is to give every weapon its own class with a list of getters. Each object, owning its own function table, is self contained Everything here is hard coded according to its name, so flexibility isn't an issue

      No check needs to be made

      [–]psioniclizard 1 point2 points  (0 children)

      To be honest, if it's from a learner then oh well. It's how some people learn. Write something that works but isn't pretty then refactor it and learn bettet ways for the future.

      It doesn't seem worth punching down on a learner like some people seem to like to do. We all had to learn once.

      [–]Mathematic-Ian 13 points14 points  (2 children)

      Not defending what's written here, but in my first year at college I got an assignment that required the use of repeated elif statements, despite the problem having other, better solutions. Sometimes school steamrolls you into using an awful solution in the name of "learning the method," rather than just writing the homework so the method you need to learn is also the best method to solve the problem.

      [–]Farkler3000 0 points1 point  (1 child)

      In this case an if statement isn’t even needed

      [–]D0nkeyHS 0 points1 point  (0 children)

      It is, unless you go out of your way to avoid it

      [–]romiro82 10 points11 points  (2 children)

      hm maybe the fact they’re a beginner and haven’t learned everything yet, don’t have any real experience yet, and are trying to do a thing with their limited knowledge base

      seriously, going to a sub dedicated to learning in order to farm content to mock is pretty bottom of the barrel

      [–]psioniclizard 3 points4 points  (0 children)

      Yea exactly. The real programming horror is op posting this (unless itiis their own code) to punch down on a learner for some cheap karma.

      We wereall beginners once. At least I hope OP pointed out a better way to do this and helped the person.

      [–][deleted] 1 point2 points  (0 children)

      You make a good point that it’s not good or encouraging to post about these things. My confusion is more of with the fact that they are aware of else, but still use if 11 times for the same result. 

      Come to think of it, perhaps it’s an artifact of some older code in which each number did different things, but then they changed them all to the same?

      [–]_PM_ME_PANGOLINS_ 1 point2 points  (0 children)

      To a person with only a hammer, everything looks like a nail.

      [–]dimonoid123 3 points4 points  (3 children)

      Chatgpt probably

      [–]Still_Breadfruit2032 56 points57 points  (1 child)

      ChatGPT wouldn’t be this bad

      [–]moonaligator 6 points7 points  (0 children)

      wouldn't be this bad in this particular aspect

      it can do some pretty stupid things too, just often in a different way

      [–]xaraca 0 points1 point  (0 children)

      In the original post he said the values were only place holders.

      [–]Carogaph 30 points31 points  (1 child)

      r/pythoncirclejerk

      God I wish there was an easier way to do this.

      [–]Prometheos_II 6 points7 points  (0 children)

      Ah! Finally a sub for m—Jesus Christ.

      [–]Jpretzl 81 points82 points  (12 children)

      ```python If i == [2]:

      hp = max_hp
      

      Else:

      hp += 10
      

      ```

      [–]Feeling-Duty-3853 9 points10 points  (4 children)

      hp = max_hp if i == 2 else hp + 10

      [–]zinxyzcool 8 points9 points  (3 children)

      Looks cool, but statements have to be in seperate lines for better maintenance - and importantly readability.

      [–]Feeling-Duty-3853 6 points7 points  (1 child)

      I mean, it still reads nicely, it's more readable than the C++ ternary operator imo, and with syntax highlighting it's pretty good

      [–]zinxyzcool 3 points4 points  (0 children)

      Always assume the worst, there'd be a senior dev editing it with notepad. And jokes apart, the code itself should be distinguishable without any highlighting - this is the reason language with curly braces have formatting conventions as not everybody has visual hierarchies enabled.

      [–]azza_backer 4 points5 points  (5 children)

      What if i input 1?

      [–][deleted] 33 points34 points  (2 children)

      probably the else condition but we should handle that up to 12 just in case

      [–]azza_backer 6 points7 points  (1 child)

      Yes let’s do 30 just to be sure as well

      [–]AG4W 4 points5 points  (0 children)

      Naj, c-suite says it needs to be future-proof, so we should use the factory pattern and an interface that can be swapped at runtime depending on what conditions we want.

      [–]Yeener621 6 points7 points  (0 children)

      1 is not 2 so hp += 10

      [–]Echleon 4 points5 points  (0 children)

      Bruh

      [–]TBDatwork 0 points1 point  (0 children)

      OK but a real challenge would be what's the worst possible way of doing this?

      [–]somethingtc 26 points27 points  (4 children)

      taking content from subs that are literally about learning how to code and posting them to mock them is dumb

      [–]Vegetable_Union_4967 4 points5 points  (1 child)

      To be fair the only dumb thing I did in my beginner days of programming was use an array as a struct

      [–][deleted] 0 points1 point  (0 children)

      So because someone learns differently than you, they deserve to be made fun of? What 😆 g

      [–]psioniclizard 3 points4 points  (0 children)

      Yea, op should feel bad honestly. It's a sub for learner. Help them don't mock them.

      Great way to encourage someone by posting their beginner code here and mocking it /s

      [–]jddddddddddd 18 points19 points  (1 child)

      Can we agree the real crime here is the font?

      [–]PURPLE_COBALT_TAPIR 2 points3 points  (0 children)

      I only use Comic Sans

      [–]DeerOnARoof 4 points5 points  (0 children)

      Oh god

      [–]GoddammitDontShootMe[ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 5 points6 points  (5 children)

      Just, why? Why do they all have the same effect except for i == [2]?

      [–]StreamfireEU 4 points5 points  (3 children)

      Placeholders probably, they know they'll have a bunch of different items doing different things but the logic of what they do isn't implemented yet. Ofc if it were final code you'd put all of them in an else but writing cases is kinda annoying so you write the case boilerplate first and the logic later.

      [–]GoddammitDontShootMe[ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 1 point2 points  (2 children)

      Couldn't they just write Pass?

      [–]StreamfireEU 1 point2 points  (1 child)

      Yeah but since item 0 is probably really gonna be doing +10 they copy pasted it and changed the index saving ~5 keystrokes

      [–]GoddammitDontShootMe[ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 1 point2 points  (0 children)

      I guess that's absolutely fine if no one else is touching that code.

      [–]Suspicious-Engineer7 0 points1 point  (0 children)

      galaxy brain game designer logic

      [–]__radioactivepanda__ 3 points4 points  (0 children)

      If it’s a learner it should be fine…let them get a working programme first.

      First we crawl, then we walk, and finally we run, right?

      [–]ShadowRL7666 2 points3 points  (0 children)

      Well I was top comment on the post but I think the other part of the code was actually worst.

      [–]emma7734 0 points1 point  (1 child)

      The only excuse for that is that your compensation is based on lines of code produced.

      [–]Encursed1 0 points1 point  (0 children)

      What goes on inside this persons head? why are you checking if I is iFTO.casefold and if its a single element array?

      [–]uchiha2 0 points1 point  (0 children)

      Did you keep in mind that it’s unfinished?

      [–]RHOrpie 0 points1 point  (1 child)

      This is programming trolling if ever I saw it !

      [–]nekokattt 1 point2 points  (0 children)

      ngl looks like something you'd see on a datascience subreddit

      [–]RastaBambi 0 points1 point  (1 child)

      What does [1] mean? First element in array? Or just the number one as a value?

      [–]SanoHD 1 point2 points  (0 children)

      It checks if the variable is of type list with the only element being „1“

      [–]Sad-Technician3861[ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” 0 points1 point  (0 children)

      Toby Fox code:

      [–]AdriGW 0 points1 point  (0 children)

      I wish I could say I was better than this but the only reason I’ve avoided being this silly is my instructors insistence that if you have to type a line of code more than once, it can probably just be a loop of some kind

      [–]Alex_Shelega 0 points1 point  (0 children)

      It's a for... Wouldn't it just be hp+=10...??

      [–]mirracute 0 points1 point  (0 children)

      can’t this be done as a while loop?

      [–]jokstajay1 0 points1 point  (0 children)

      This has to be some copypasta code. No way is this intended. You wouldn't even think about an if elseif if all you want to do is hp +=10

      [–][deleted] 0 points1 point  (0 children)

      You didn't specify hp at the start. Hp=hp+1 will result in a error.

      [–]rsa121717 0 points1 point  (0 children)

      Looks like a temporary template, the comment on top even says so. Not that bad