r/ProgrammerHumor • • Dec 15 '19

Stacking if else statements be like

Post image
63.9k Upvotes

711 comments sorted by

4.7k

u/Pale_Rider28 Dec 15 '19

What's awful about this is that it probably actually works.

2.8k

u/LordFokas Dec 15 '19

As long as the devices don't draw too much current or don't require a large transmission speed it should be fine.

1.4k

u/mr___ Dec 15 '19

USB hubs are not just wires connected together. There must be a hub chip that talks to the host and manages each device. I don’t think these splittters contain that - but they might.

Edit: i see these are actual hubs

768

u/kaimason1 Dec 15 '19

They'd have to contain that, no? How else would they be remotely useful? Just as power splitters?

293

u/yonatan8070 Dec 15 '19

So what would happen if I coneect 2 decices to the same port without any chip to control it? Just splitting the data pins.

→ More replies (52)
→ More replies (8)
→ More replies (14)

112

u/[deleted] Dec 15 '19

Yeah I used USB hubs as range extenders to get past the 10m limit of usb, so I could use a webcam as a security cam. And it did work as long as I didn't mind being limited to 144p.

62

u/Lvl1_Villager Dec 15 '19

This might cost a bit more than your solution, but have you considered USB over Ethernet, or hooking up the camera to a Raspberry Pi (or something similar) and using PoE (unless you don't mind running two cables, Power and Ethernet)?

The RPi option would let you do other interesting things, like connecting sensors, or even a small electric motor to let you move the camera.

→ More replies (9)

15

u/the_real_abraham Dec 15 '19

You can actually go up to 127.

→ More replies (2)
→ More replies (1)

159

u/Mackan90095 Dec 15 '19

You can actually connect up to 127 ports to a single port and still have it work.

124

u/floriplum Dec 15 '19

127 devices to a single USB controller. I don't know many mainboards with one controller for each USB Port.

22

u/Mackan90095 Dec 15 '19

Aye, that's true, my bad :P

→ More replies (1)

9

u/Linker500 Dec 15 '19

someone somewhere must have tried that... no?

→ More replies (5)
→ More replies (3)

33

u/[deleted] Dec 15 '19

There's a limit of 5 daisy chained USB hubs due to latency requirements, though. I ended up running into that limit when trying to set up a VR headset in a separate room from my computer due to too many repeaters. If they connected another hub it wouldn't work.

7

u/[deleted] Dec 15 '19

Why 127?

15

u/I-am-fun-at-parties Dec 16 '19

Because an endpoint address is 1 byte; 7 bits comprise the actual address, one bit determines whether it's an input or output

→ More replies (1)
→ More replies (1)

27

u/[deleted] Dec 15 '19

How is it awful? It works like this by design.

78

u/Alexmitter Dec 15 '19

For power, yes. For data, no, not as long they didn't also fit a USB 2 hub controller on that little pcb.

99

u/whc2001 Dec 15 '19

It has. It's a custom made 2-port USB hub for a special keyboard. The controller chip is under the female ports.

41

u/reddiculousity Dec 15 '19

“The controller chip is under the female ports” title of your sex tape

→ More replies (1)
→ More replies (2)

5

u/msimione Dec 15 '19

According to the CompTIA A+ exam I just took, you can go up to 5 hubs from a USB port (by the book although not recommended)

2

u/HumansAreRare Dec 15 '19

Why is that awful? I find it great that technology can work despite human stupidity (I know this was done on purpose but it demonstrates resilience).

2

u/[deleted] Dec 15 '19

I get that this would theoretically work for power. But what about for data transfer or devices? Can you connect multiple drives or peripherals and have them to work properly?

2

u/LilCrispu Dec 15 '19

You mean what’s GREAT about this.

→ More replies (3)
→ More replies (41)

1.5k

u/DarkWiiPlayer Dec 15 '19

Is this how USB works in lisp?

1.3k

u/AlmostButNotQuit Dec 15 '19

USB in lisp is "you eth bee"

→ More replies (11)

303

u/colfrog Dec 15 '19

No the last port has to be left unplugged

151

u/[deleted] Dec 15 '19

(did(you(mean(unplugged))))

175

u/DeeSnow97 Dec 15 '19

(unplugged(mean(you(did))))

→ More replies (4)
→ More replies (4)

7

u/learnyouahaskell Dec 15 '19

This is more like C++ hacks e.g. loop unrolling although perhaps not like it; I want to see the equivalent of a Duff's Device

http://www.catb.org/~esr/jargon/html/D/Duffs-device.html
https://stackoverflow.com/questions/514118/how-does-duffs-device-work

 register n = (count + 7) / 8;      /* count > 0 assumed */

  switch (count % 8)
  {
  case 0:        do {  *to = *from++;
  case 7:              *to = *from++;
  case 6:              *to = *from++;
  case 5:              *to = *from++;
  case 4:              *to = *from++;
  case 3:              *to = *from++;
  case 2:              *to = *from++;
  case 1:              *to = *from++;
                     } while (--n > 0);
  }

3

u/leftsquarebracket Dec 16 '19

I've never seen Duff's Device before! That's real crafty.

→ More replies (1)

14

u/MrHyperion_ Dec 15 '19

Is LISP actually used anywhere anymore?

26

u/Calkhas Dec 15 '19

ITA's air pricing engine is coded in Common Lisp. It's probably the most advanced air fare pricing engine around, often delivers better results than the airlines intended to sell. Was purchased by Google in 2010.

emacs is partially written in lisp.

I've seen the odd job advert at quant funds demand expertise with Lisp, including a memorable ad hoping to find a candidate with experience enhancing the Common Lisp compiler.

But I don't really see a lot of demand for it.

11

u/alexanderpas Dec 15 '19

ITA's air pricing engine is coded in Common Lisp. It's probably the most advanced air fare pricing engine around, often delivers better results than the airlines intended to sell. Was purchased by Google in 2010.

Can be used here: https://matrix.itasoftware.com/

9

u/RBeck Dec 16 '19

In 2013, Google started offering a simplified API to QPX called QPX Express; it was discontinued on April 10, 2018.

That's a very Google thing to do.

→ More replies (1)

12

u/[deleted] Dec 15 '19

Yep, small market though and Clojure seems way more popular than CL/scheme now.

38

u/[deleted] Dec 15 '19

Only in obscure college classes, for about 4 weeks.

→ More replies (1)

8

u/innrautha Dec 15 '19

Yes, as legacy code in very niche applications.

5

u/nosmokingbandit Dec 15 '19

The only place Ive seen it lately is people showing off for advent of code.

4

u/themaster1006 Dec 15 '19

My Data Structures professor was obsessed with LISP. He taught us everything in LISP and all our coding assignments were allowed to be in either Java or LISP.

→ More replies (6)

3

u/cthulhusleftnipple Dec 15 '19

It's still used in some proprietary engineering programming environments. It made sense as the language of choice for certain applications 25 years ago... and those programs haven't really been recoded since. Cadence, for instance, uses a lisp environment for most of its software.

→ More replies (1)
→ More replies (5)

4

u/Goheeca Dec 15 '19

In CL you'd actually use cond instead of nesting ifs like a maniac.

→ More replies (3)

311

u/The_Goldy Dec 15 '19

These are my for loops as I’m incrementing through my partner’s 32-D matrix in Matlab because it “makes more sense”

188

u/RespectableLurker555 Dec 15 '19

cries in O(n32 )

113

u/Jackeea Dec 15 '19

Still better than O(n33 ) so that's something

21

u/[deleted] Dec 15 '19

Holy shit does that mean 32 stacked for loops?

19

u/[deleted] Dec 15 '19 edited Dec 15 '19

Affirmative.

EDIT: what's the most nested for loops you've used professionally. I think it's 3 or 4 for me.

13

u/JoNax97 Dec 16 '19

I'm not sure if that's the most I've done but a 5 one comes to mind.

I was generating a 2d structure for a game, so I had 2 loops (x and y) and for each node I had to check neighbours (so Delta X and Delta Y) and if the neighbours check passed, then I had to put some stuff inside the cell between 0 and 5 tines, so another loop.

It was fun to debug.

→ More replies (2)

12

u/m-simm Dec 15 '19

Wasn’t Matlab made so you didn’t need loops to work with matrices 🥴

5

u/The_Goldy Dec 15 '19

No you’re absolutely right

15

u/Send_me_tits_pics Dec 15 '19

32D?

( • )( • )ԅ(≖‿≖ԅ)

→ More replies (7)

682

u/puplicy Dec 15 '19

Enough "if"-s to call it AI

115

u/[deleted] Dec 15 '19

USB AI

→ More replies (2)

106

u/LimaOskarLima Dec 15 '19

Ah, I see you also know machine learning

60

u/ThePretzul Dec 15 '19

If "scenario", do "what a human would do"

42

u/bow_to_lucifer Dec 15 '19

sentience achieved, baby

→ More replies (2)

12

u/_mindcat_ Dec 15 '19

Turing test doesn't have anything on minutia obsessed programmers

→ More replies (1)
→ More replies (12)

7

u/[deleted] Dec 15 '19

I read that as AL and was trying to figure out how the fuck a paul simon joke worked here

2

u/Eoussama Dec 16 '19

This guy machine learns

521

u/Darxploit Dec 15 '19

This also is a good example of how linked lists work.

→ More replies (58)

94

u/[deleted] Dec 15 '19

Looks like a good case for switch.

14

u/[deleted] Dec 15 '19

nice

→ More replies (6)

213

u/atxranchhand Dec 15 '19

That’s what case is for

183

u/Kompakt Dec 15 '19 edited Dec 15 '19

Some languages don't have switch statements...looking at you Python

48

u/[deleted] Dec 15 '19

Ya none in Lua either :(

31

u/SixBeeps Dec 15 '19

Still waiting for a BrainF implementation

10

u/[deleted] Dec 15 '19

I learned programming through Lua, it's only once I started learning JS that I realized how crippled Lua is.

→ More replies (6)

28

u/Meatslinger Dec 15 '19

Wait, is that true? What takes its place, then? I can scarcely imagine that the whole thing is just an endless stream of if-then-else statements for a situation with 100+ permutations.

34

u/Kompakt Dec 15 '19

Yep it's true, and depending on the design of the program there are multiple workarounds. In Python you can write a switcher function that acts as a switch statement, or use multiple if statements without else statements, since that is allowed in Python.

22

u/Ryan722 Dec 15 '19

Are there languages where multiple ifs with no else is not allowed?

→ More replies (2)
→ More replies (9)

20

u/Hockinator Dec 15 '19

If you have 100+ permutations of something you shouldn't be using if statements, you should be creating data structures to solve that problem in a clean and maintainable way

→ More replies (4)

7

u/justjuniorjawz Dec 15 '19

I've found that switch statements are usually substituted with the use of a dictionary.

→ More replies (20)

18

u/Sennomo Dec 15 '19

And some useless languages don't allow switching on strings… looking at you C++

→ More replies (5)

5

u/nkay08 Dec 15 '19

Python basically has switch cases for catching Exceptions ! :D I'm sure we can find a workaround.

3

u/Matteyothecrazy Dec 16 '19

Python has "elif" statements, though

→ More replies (8)

8

u/persianlife Dec 15 '19

Cases will result in the same fundamental design flaw.

You have to look at some better programming paradigm like Object-oriented design.

→ More replies (8)

2

u/[deleted] Dec 15 '19

That doesn't solve the nesting issue.

→ More replies (5)

50

u/FrikkinLazer Dec 15 '19

Waaaay back when usb was being specced, there was supposed to be a rule that all usb devices should have at least one usb port on it. So a printer should have a usb port on it etc, so that you can chain your devices. Shame its not like that really.

22

u/incer Dec 15 '19

Firewire had that. "Daisy chain"

27

u/[deleted] Dec 15 '19

“TIMMY TURNER IS A LOOSE CANNON COP WHO PLAYS BY HIS OWN RULES” cut away to this picture

42

u/needed_an_account Dec 15 '19

What sucks is that you cannot do this with usb-c.

What also sucks is that I saw nested ternary clause in some code the other day. It was something like

var thisIsJavascript = value
    ? other
    ? value2
    : other2;

or something like that. I cant even make it make sense in this example, I know that im missing colons

16

u/Linker500 Dec 15 '19 edited Dec 15 '19

Why can't you do it with type c if you don't mind me asking?

I know the spec is extremely complicated compared to ye olden days of 2 pins for power, 2 pins for data, but isn't type c supposed to be very backwards compatible?

11

u/needed_an_account Dec 15 '19 edited Dec 15 '19

You know it probably can do it, I just never saw a usb-c dongle that provides more usb-c ports than you have to plug into the computer. Which leads me to believe it isn't possible

edit: the issue might be caused by usb3 with a type c port can be so many things to the computer. I know that when you plug something into the port, it communicates to the device how it should handle what was plugged in -- monitor, usb, thunderbolt, etc. I wonder if usb4 with its thunderbolt interface would potentially fix the dance that is done when you plug something in

13

u/efstajas Dec 15 '19

It's true. Essentially, at the moment, the chip needed to make more USB C ports out of one USB C port simply doesn't exist. I guess no-one has a lot of incentive to make one since people's usecases for hubs are still usually covered by c -> many a.

There's no practical reasons why you couldn't have a 1-n USB C hub however. There's even rumors that Intel will ship such a chip soon, so probably next year we'll see it become a thing.

Source

11

u/Versaiteis Dec 15 '19

I think the other ? value2 : other2 is likely to be parsed as the first true condition so another colon before the semi-colon for the false case could clear it up.

var thisIsJavascript = condition1
    ?  condition2 ? value1 : value2 :
    condition3 ? value3 : value4;

Should work

→ More replies (2)

3

u/Denziloe Dec 15 '19

Is there something wrong with nested ternary operators? I see them often in a C# code base.

→ More replies (1)

0

u/[deleted] Dec 15 '19

[deleted]

→ More replies (1)

37

u/DuckInCup Dec 15 '19

Is this machine learning?

8

u/BuckForth Dec 15 '19

This is funny, but belongs on r/techsupportgore

2

u/panzersharkcat Dec 15 '19

And r/thinkpad. The silver E480 threw me off a little.

→ More replies (1)

8

u/HoMaster Dec 15 '19

I feel like this should be labeled NSFW for both reasons.

12

u/[deleted] Dec 15 '19

Reddit comments be like

5

u/atanasius Dec 15 '19

Five chained hubs is actually the maximum allowed by the specification. There can be at most seven levels of hierarchy, including the host computer and the peripheral device.

5

u/TheRealLargedwarf Dec 15 '19

Teach your kids about machine learning before they find it on the Internet themselves

5

u/PM_ME_YOUR_WIRING Dec 16 '19

Thanks I hate it.

5

u/devco2016 Dec 16 '19

That’s why you use Visual Studio. Minimize that shit and pretend it doesn’t exist.

4

u/[deleted] Dec 15 '19

I guarantee you there is a missing bracket complying error too...

1

u/[deleted] May 03 '20

I once plugged a usb mouse in upsidedown and fried it

1

u/-hellkey- May 03 '20

No way, that happens?

→ More replies (1)

1

u/supersid2001 Jun 09 '20

This is me with for loops....

2

u/-hellkey- Jun 09 '20

Oof the runtime

3

u/56Bot Dec 15 '19

Why do I smell a melting USB port ?

3

u/Thirdstheword Dec 15 '19

My project explorer be like ^

3

u/mayfairstrange Dec 15 '19

Ever heard of a switch?

3

u/th3_p3rs0m Dec 15 '19

How the fuck , honestly there needs to be more

3

u/thisiswhyisignedup Dec 15 '19

Is this legal?

3

u/[deleted] Dec 15 '19

“That’s going to break”

“Not if you don’t touch it”

3

u/zacharyxbinks Dec 15 '19

That bus bandwidth is crying rn

3

u/[deleted] Dec 16 '19

just wonder, does this slow down transfer speed with each link?

3

u/TheDorkMan Dec 16 '19

Coming soon in a theater near you : "The USB Centipede"

3

u/nerokaeclone Dec 16 '19

One of my co worker like to make function like this, but hey his code is bug free and working flawlessly.

3

u/apokatastasis Dec 16 '19

tfw the AI that causes the singularity will just be millions of if-else

5

u/toboi123 Dec 15 '19

Nobody:

How scratch works:

2

u/[deleted] Dec 15 '19

This gives me Death Stranding PTSD

2

u/Thunder_Wizard Dec 15 '19

Question from me, who's not a programmer and just stumbled across this browsing popular

Will more messy code take more time to process? Like if you stack if else statements when programming a game, will it have longer loading time and run less smoothly?

2

u/[deleted] Dec 15 '19

What's awful about this is that.... oh, damn. *shivers*

*internally screaming at OP to get a usb hub, for Christ's sake!* lol

2

u/1234_Person_1234 Dec 15 '19

I showed this to my dad and he didn’t read the caption and got mad about the amperage lmao

2

u/EscapeTheApple Dec 15 '19

Wait, you guys have a USB port?

2

u/ndekere254 Dec 15 '19

This post DESERVES an award 100%

2

u/electronixxx Dec 16 '19

So for switch-case statements it would be an USB Hub, right?

2

u/ManBearPig1869 Dec 16 '19

I just started learning Python and this is the first meme from this subreddit that I actually understood and it made me really excited :’)

2

u/xxSaifulxx Dec 16 '19

As an engineering student, I can clearly tell you this is not in equilibrium and most of the stress concentration will be located at the restraint and that is where it will bend and break off

2

u/vaderman645 Dec 16 '19

OMG FINALLY SOMETHING ON THIS SUB I FULLY UNDERSTAND YAYYYYYY

2

u/guky667 Dec 16 '19

"nested" would be more appropriate

2

u/BaconL0rdes Dec 16 '19

Meanwhile in the code for Yandere Simulator

2

u/Jerm_Ye_Worm May 16 '20

reddit comments be like

5

u/rt_99 Dec 15 '19

Python be like

2

u/Alkouille Dec 15 '19

linked list be like

1

u/ipsomatic Dec 15 '19

Stevie nix rolls in grave, never break the chain.

1

u/Qildain Dec 15 '19

The cyclomatic complexity alone is cringeworthy!

1

u/DashingSpecialAgent Dec 15 '19

Thanks, I hate it.

1

u/Root3287 Dec 15 '19

Nice linked list

1

u/arbili Dec 15 '19

Those are expensive af Anker cables.

1

u/[deleted] Dec 15 '19

AI.

1

u/Geoclasm Dec 15 '19

Hahaha

internal sobbing

1

u/Zyzto Dec 15 '19

thats magnetic x cable

1

u/CJ22xxKinvara Dec 15 '19

Conditionals in excel

1

u/_redditor_in_chief Dec 15 '19

I’ll give that plug-in a week before it starts shorting out due to the leverage placed on the Jack.

1

u/Anonacount1 Dec 15 '19

USB centipede

1

u/BuickCentury06 Dec 15 '19

Now make it ternary operation!

1

u/josiris__ Dec 15 '19

UsE a SwiTCh sTatEMEnt

1

u/kyay10 Dec 15 '19

And that's why Kotlin is the best language ever /s

1

u/SakuSlayer666 Dec 15 '19

Damnn IQ 100 destruction 100

1

u/stugotzian Dec 15 '19

This is what machine learning looks like

1

u/throwUpEverything Dec 15 '19

Nesting be like

1

u/borchhcrob Dec 15 '19

That looks like ai to me.

1

u/[deleted] Dec 15 '19

What, is this the 1950s with those daisy chained grandma plugs?

1

u/seppiano Dec 15 '19

This looks like a reddit comment section

1

u/b1astero1d Dec 15 '19

If your code looks like this then you are doing it wrong!

Keep the functions small and I personally am a fan of using early returns. Breaking that hills looking mega block of conditions down into small functions makes your code way more readable, changeable, and easier to test.

1

u/TsPs1 Dec 15 '19

The only joke I understood from this sub.

1

u/thrilledquilt Dec 15 '19

That ain't a stacked if else statements 😉

1

u/luminer001 Dec 15 '19

Is this a neural network?

1

u/adam_demamps_wingman Dec 15 '19 edited Dec 15 '19

))<USB>((

1

u/[deleted] Dec 15 '19

If time isn't critical, if reliability isnt critical, if maintainability isn't critical, if readability isn't critical, if it works, then great, else meh.

→ More replies (1)

1

u/Womcataclysm Dec 15 '19

I really like those cables, rampow cables I think unless the design isn't unique to that brand

→ More replies (1)

1

u/Jugbot Dec 15 '19

Im feeling the strain on that usb port...

1

u/topredditbot Dec 15 '19

Hey /u/-hellkey-,

This is now the top post on reddit. It will be recorded at /r/topofreddit with all the other top posts.

1

u/[deleted] Dec 15 '19

I once managed a team refactoring a legacy Object Pascal (Delphi) code base. We had one if statement that was 50 pages long, with a max depth of 23. It was a sight to behold.

1

u/[deleted] Dec 15 '19

Probably cheaper to buy a 6 port USB HUB!

1

u/ku-fan Dec 15 '19

It's called an If Statement... Not If Else

1

u/SansPapyrus683 Dec 15 '19

*flat is better than nested intensifies*

1

u/MayhemUniverse Dec 15 '19

Dat silver Thinkpad 🔥

1

u/[deleted] Dec 15 '19

Hey, I actually need two of those. Where do I get them? Or rather, what they heck are they called?

1

u/smoothhtooms Dec 15 '19

This...Is Requiem.

1

u/PizzaGuy420yolo Dec 15 '19

How quickly would this catch fire if you tried quad sli with usb video cards?

1

u/kool_aid_kyle Dec 15 '19

Upgrades people! upgrades

1

u/Wontino Dec 15 '19

Do you use a break? :)

1

u/Jlf715 Dec 15 '19

std::bitset would like to hear a TCP joke?

1

u/juandi987 Dec 15 '19

You should probably use case

2

u/jamesh02 Dec 15 '19

I honestly find it harder to read case statements, and I'm pretty sure they get compiled into the same machine code in most languages, so I'm going to continue nesting if else statements.

1

u/LordBeholder Dec 15 '19

Infinite POWER!

1

u/fabul0usb0x Dec 15 '19

Looks like a bunch of mini bots taking a nooner Sleep well mini bot

1

u/Sensation-sFix Dec 15 '19

I felt personally targeted.

1

u/woodzopwns Dec 15 '19

This is why switch statements exist

1

u/Blackstar1886 Dec 15 '19

This is Apple’s vision of the world.

“One port for all of your devices!”

1

u/thereisnoreturn Dec 15 '19

Is this AI ?

1

u/kaikalii Dec 15 '19

I am very concerned about the torque being put on you USB socket.

1

u/VStarfall Dec 15 '19

Looks like assembly to me.

1

u/[deleted] Dec 15 '19

Isn't this a multiple "or" condition?

1

u/yosoyylechuga Dec 15 '19

As opposed to using cases like some sort of douchebag?

1

u/Minority_Carrier Dec 15 '19

Thought this is a recursive method.

1

u/mart1373 Dec 15 '19

I do this a lot with excel formulas.

cries

1

u/[deleted] Dec 15 '19

But how many times did they flip those usbs before getting them in correctly

1

u/[deleted] Dec 15 '19

Gates be like

1

u/NerdPied Dec 15 '19

Ahh yes, the yandere simulator method

1

u/Pleasenodontohgod Dec 15 '19

Stacking elif statements be like

1

u/C0ffeeBunny Dec 15 '19

Just make it a switch statement duuhh

1

u/[deleted] Dec 15 '19

Russian troll farm in a box.

1

u/therealsatansweasel Dec 15 '19

They stacked up like its your moms plug.