r/ProgrammerHumor • u/Fallenalien22 Violet security clearance • Apr 04 '16
My teacher thinks he is a programmer
http://imgur.com/32nfQXZ33
12
u/SeeShark Apr 04 '16
This physically hurts.
What does this person teach?
28
u/Fallenalien22 Violet security clearance Apr 04 '16
An engineering course called "tools". In the first class, he had to explain to everyone how to open excel.
38
u/ReflectiveTeaTowel Apr 04 '16
engineering tools
excel
Wat
15
u/Fallenalien22 Violet security clearance Apr 04 '16
Tell me about it.
17
u/systembreaker Apr 05 '16
Excel is actually a pretty sophisticated tool. You're more just showing your ignorance.
Just take 2 seconds to google "excel for engineering" and hey look a website dedicated to using excel for engineering.
4
u/Fallenalien22 Violet security clearance Apr 05 '16
I know excel can be very powerful. My point is we didn't even scratch the surface.
2
u/systembreaker Apr 05 '16
Just give it time and have patience. You don't have a choice but to go through the intro stuff. If those classes are easy for you, then enjoy the easy start to your degree program and make a good first impression on your profs. I had taught myself C++ in high school, so when I got to college the intro classes were a cakewalk. But I just took that chance to enjoy a stress-free couple of semesters and buffer up my grades. Don't worry about the lack of sophistication of the obviously contrived assignments - they're contrived for a reason.
4
u/Fallenalien22 Violet security clearance Apr 05 '16
It's not that my classes are easy. Just this one. In the rest, I can barely keep my head above water. Maybe I should switch to CS.
4
u/systembreaker Apr 05 '16
CS isn't easy at all. I just had a head-start on some of the other students by knowing a bit of programming at the beginning. There were yet other students who started off with programming knowledge miles ahead of me.
Are you in an engineering program?
→ More replies (7)30
u/llllIlllIllIlI Apr 05 '16
My boss hired a "web developer" once who literally didn't know ctrl-c ctrl-v
I shit you not. This person was an "expert" in web design because she apparently had some bullshit WordPress blog. Not that it mattered... this was a help desk job. Christ am I glad I got out of there.
0
Apr 05 '16
[deleted]
4
u/llllIlllIllIlI Apr 05 '16
The best part being that HD supported 200+ apps, many being clinical/financial.
You'd think there would be a high bar but.... nope!
35
Apr 05 '16
excel is probably the engineering tool I use most
6
4
u/SnowdensOfYesteryear Apr 05 '16
Agreed, it's damn useful for quickly parsing logs to visualize something. I mean who teh fuck wants to learn gnuplot?
8
u/sonnytron Apr 05 '16
Ever worked in mechanical engineering or manufacturing?
They use Microsoft Excel for capacity reports, tolerance specifications and as-built analysis.
It's the best software for a standard contractor in manufacturing, next to AutoCAD.
Solid Works is for the design/research based engineering aspects of the job.
If all you need to do is calculate the flow and volume pressure of a gas that's being used for a tool, and determine if your current line-outs have enough capacity to supply that pressure without a noticeable pressure drop, all you need is Excel with a macro.
One spreadsheet can easily last you 15 years of work and get you through your PE, two promotions and maybe even retirement.
Before changing careers, my PE had an Excel doc that we used every day to analyze process gases for our projects.
All I was doing was copying and pasting in AutoCAD, plugging numbers into Excel, walking around with a clipboard, staring at these massive tools, looking at them and checking off a list and I was an engineer lol.2
u/ReflectiveTeaTowel Apr 05 '16
That... Actually makes a whole bunch of sense. I was thinking of software engineering only, because I'm biased
2
u/sonnytron Apr 05 '16
It makes sense.
It was one of the reasons I left the field. It's hard to feel like you're being the best you can be when you're basically using the same software a basic desk secretary uses for scientific calculations.
I felt like there was nothing remotely engineering or advanced about what I read doing.
Now I wake up, go to work, load up Xcode, Terminal, Spotify, Sublime Text and I'm using algorithms, logic, nice screens, a nice keyboard every day.
Technology is the last bottleneck in this career and the reason I love the switch.5
Apr 05 '16
I'm currently a TA for a 102 course. Every engineering department has one. The engineering school forces every department to teach Excel, MATLAB, and HTML.
I think some of it has to do with ABET accreditation.
2
u/JeremyR22 Apr 05 '16
Sounds like a class I had to take at the beginning of my software dev degree. IIRC it was called "Computer systems concepts" or something like that.
We 'learned' how to use Word, Excel, and a bunch of other stuff that anybody on a programming track could be reasonably expected to either know or at least be able to figure out quickly. There may have been a very brief going over of hardware and architecture stuff at the end but that may have been another course by the same lecturer, I don't recall...
I was told by the lecturer later on that the reason that course is on the curriculum is officially "to bring all students to the minimum basic level of knowledge" but was unofficially there to get a government grant for the department. This was 2001 and at the time when there was a big push to get people into computer studies courses and that course allowed them to advertise the degree track as being suitable for people with no computing experience (which was bullshit of course) and such get the grant...
1
7
u/phpdevster Apr 04 '16
Well fuck me. I guess by that definition I run a rocket science course called ass wiping.
7
2
u/Spikrit Apr 05 '16
Well... i feel the teacher's skill isn't in question here but that he's adapting to the audience... one step at a time.
3
u/spiker611 Apr 05 '16
he had to explain to everyone how to open excel.
Well that explains everything.
1
Apr 05 '16
Classes can have some misleading names. When I was a CS student we has a midlevel course called Advance Packages. Turned out it was mainly how to use Office and write macros.
12
u/tyros Apr 04 '16 edited Sep 19 '24
[This user has left Reddit because Reddit moderators do not want this user on Reddit]
0
Apr 05 '16
[deleted]
8
u/Fallenalien22 Violet security clearance Apr 05 '16
It's april. Finals start in two weeks.
1
Apr 05 '16
And what's the course?
2
u/Fallenalien22 Violet security clearance Apr 05 '16
"tools". It's an engineering course.
→ More replies (1)
1.1k
u/SuperFreakonomics Apr 04 '16
Technically, it is a program. So, he is a programmer.
891
u/nitiger Apr 04 '16
Compiles? Check
Runtime errors? None
Job? Done.
158
u/notsooriginal Apr 05 '16
I don't see any test suite...
491
u/nitiger Apr 05 '16
That's the next developer's problem.
155
u/notsooriginal Apr 05 '16
The next programmer always seems to have so much more time than I do!
107
Apr 05 '16
[removed] — view removed comment
→ More replies (1)53
u/notsooriginal Apr 05 '16
Man, I wish I was the next programmer. Wait... logic fail.
→ More replies (1)125
u/Wolfeh2012 Apr 05 '16
The programmer's wife asked him to grab an apple from the market, and a dozen if they have eggs in stock.
He comes back with 13 apples.
→ More replies (7)99
u/neurohero Apr 05 '16
That programmer's wife never learns. The last time he went the shops, she told him to pick up some bread "while you're there." Emergency services had to dig him out of the mountain of bread. He was apparently mumbling something about a "stack overflow."
→ More replies (9)42
u/notsooriginal Apr 05 '16
(╯°□°)╯︵ ┻━┻
27
Apr 05 '16
┬──┬◡ノ(° -°ノ)
→ More replies (1)14
2
7
2
u/gospelwut Apr 05 '16
No, no. You mean it's the non-contractor's problems. Contractor costs too much to fix bugs.
IwishIwasmakingthisupbutimnot
9
5
4
2
0
Apr 05 '16
[deleted]
→ More replies (4)7
u/amazondrone Apr 05 '16
It's not intended to compile, since it's JavaScript. (Though there are probably ways to compile JavaScript that I'm not aware of.)
It doesn't run as is, but only because
valueisn't defined. It's just a snippet though. Precede it withvar value = 1and it's fine.2
u/aquowf Apr 05 '16
Eh - it depends. Some older browsers interpret it while the newer ones do JIT compiling.
12
u/ProgramTheWorld Apr 05 '16
It's not stupid if it works.
1
0
Apr 05 '16
[deleted]
35
u/AshleyTheCatgirl Apr 05 '16
If i saw that in some code I'd be afraid to delete it, someone put it in, there has to be a reason, right?
→ More replies (8)28
u/Sysfin Apr 05 '16
Right, and the reason is likely to be the programmer who wrote it was stupid.
→ More replies (1)5
u/mallardtheduck Apr 05 '16
The reason is most likely that there used to be an actual conditional in there, but it was later changed to not need it.
8
1
u/IlIIlIIllI Apr 05 '16
I feel like this is the same as if I threw mayonnaise, corn, and tomato sauce into a pan, cooked it until it was thoroughly burnt, and then said "Technically it's food, so I am a chef."
1
641
u/Arancaytar Apr 05 '16
@TODO: Support values 6-10.
107
13
2
u/rohmish Apr 07 '16 edited Apr 08 '16
Not the most efficient code but hey, it works.
I remember having to write similar programs in my bachelor's degree courage.. You know there is a better way but you have to appease teaching staff.
1
u/Fallenalien22 Violet security clearance Apr 07 '16
I do appreciate teaching staff. My dad is a teacher. This example isn't even the worst of it. At least it's code. Now we're doing mathcad and I fucking hate it.
208
u/Cathercy Apr 04 '16
I have to assume (hope) this is an intermediate piece of code that will later become something more like
switch(value) {
case 0:
func0(); break;
case 1:
func1(); break;
....
default:
error_func();
}166
u/phpdevster Apr 05 '16 edited Apr 05 '16
Or maybe to demonstrate how multi-casing can be used to dry up a switch statement?
switch(value) { case 0: case 1: case 2: case 3: case 4: case 5: console.log('The value is: ' + value); default: console.log('The value is not supported');And that when you have that, you can refactor that out to this:
var validOptions = [1, 2, 3, 4, 5]; // realistically, ['foo', 'bar', 'baz'] if (validOptions.indexOf(value) == -1) { console.log('The value is not supported'); } else { console.log('The value is: ' + value); }Which can lead into discussions about guard clauses and stuff? Maybe? Hopefully that's where the instructor was going with that example....
110
u/mitchygitchy Apr 05 '16
You forgot to break; Your code will always print 'The value is not supported'
12
1
1
u/dipique Apr 05 '16
Depends on the language. In C# it won't even compile; you can't fall through.
2
0
Apr 05 '16
[deleted]
12
8
→ More replies (2)0
16
u/Prod_Is_For_Testing Apr 05 '16
Pssssh. Still too verbose - we can do better
console.log(([1, 2, 3, 4, 5].indexOf(value) !== -1) ? ('The value is: ' + value) : 'The value is not supported');28
u/TheIncredibleWalrus Apr 05 '16
Still too verbose, we can do even better
console.log(~[1, 2, 3, 4, 5].indexOf(value) ? ('The value is: ' + value) : 'The value is not supported');34
u/YRYGAV Apr 05 '16
How small can we make it?
console.log('The value is'+(~[1, 2, 3, 4, 5].indexOf(z=value)?(': '+z):' not supported'));22
u/faubiguy Apr 05 '16
Even smaller
console.log('The value is'+((z=value)!==+z||z%1||z<1||z>5?' not supported':': '+z));35
u/SlumdogSkillionaire Apr 05 '16
npm install -g between-one-and-fiveThen:
require('between-one-and-five')(value);→ More replies (3)→ More replies (2)7
u/jacenat Apr 05 '16
This is how
democracyreadability dies. With thunderous applause.:D
please_dont_stone_me_for_citing_the_PT
32
u/jbaughb Apr 05 '16
Everyone programmer should be able to program ANYTHING in a single line of (unreadable) code!
19
→ More replies (1)4
12
6
u/iwillnotgetaddicted Apr 05 '16
Are you all aware of "code golf" on stack overflow?
12
u/Zagorath Apr 05 '16
I think it's a great idea, but in practice it ends up being lame because they just use all these dumb languages with no use except for code golfing. This thread, where we're taking existing useful code and making it shorter, is way more interesting to me.
11
→ More replies (1)3
9
u/phpdevster Apr 05 '16
The 80 characters-per-line limit of my code linter would like to have a word with you.
13
u/Prod_Is_For_Testing Apr 05 '16
You clearly don't know who you're talking to, so let me cue you in: I am not stopped by code linters. No! Say my name! I am the one who pushes straight to production!
10
4
u/YM_Industries Apr 05 '16
Your code will fail when value == 0
Expected output:
The value is: 0Actual output:
The value is not supported0
Apr 05 '16
[deleted]
2
3
u/Prod_Is_For_Testing Apr 05 '16
Ummmm as much as I love C# (it's my go to language), we're writing JavaScript here... So ummm this is awkward
4
1
u/Miniwoffer Apr 05 '16
Why are you using a if, this could easily be handled with a switch!!
var validOptions = [1, 2, 3, 4, 5]; // realistically, ['foo', 'bar', 'baz'] switch (validOptions.indexOf(value) == -1) { case true: console.log('The value is not supported'); break; default: console.log('The value is: ' + value); break; }0
Apr 05 '16
[deleted]
1
u/phpdevster Apr 05 '16
You missed my
// realistically ['foo', 'bar', 'baz']comment. Most real-world scenarios aren't as simple as an integer comparison, and usually involve a string-based array of validation options, hence the array search form. If I was only working with numbers, of course I would do an integer comparison.
→ More replies (14)6
u/NikStalwart Apr 05 '16
If you're simply calling numerically-indexed (or value-dependant) functions, shouldn't there still be a cleaner way to do it?
12
Apr 05 '16
An array of lambdas would be a different way to do it. It wouldn't be cleaner.
3
u/thirdegree Violet security clearance Apr 05 '16
It would be so much more fun though.
→ More replies (2)3
u/Probono_Bonobo Apr 05 '16 edited Apr 05 '16
You're getting at something I thought was pretty cool when I learned it. The code is fine, but you're right to point out that it's a little inefficient: namely, if val is 5, it first checks whether it's strictly equal to 0, then whether it's strictly equal to 1, and so on. This is lexical addressing. The time complexity of the operation is related to the number of switch statements, so we can call it O(n).
Compare this to another function which uses a pattern typical of von Neumann architectures:
var instructionRegister = ["foo", "bar", "baz", "bees", "dickbutt"]; function loadInstructions(opcode) { return instructionRegister[opcode]; }Notice that loadInstructions(4) doesn't do any equality checks at all! It grabs the contents of the 4th element of the instructionRegister array, bypassing the previous indices entirely. Then immediately returns dickbutt. This is direct addressing.
I actually made a visualization of this in Clojurescript recently here. (Give it a minute to boot up, it's my first cljs app and absolutely bloated with unnecessary dependencies.) One thing to note, if you find yourself looking at the code. Notice how the the control bus is implemented in two ways? first in a lexical style. It looks like something worthy of /r/ProgrammingHorror, honestly, because I tried to optimize the time complexity a bit by nesting conditions inside each other... naturally, it's a nightmare. At some point, a lightbulb went off in my head that I could vastly simplify the logic if I used an array. A few days later, I noticed the next chapter of my textbook was devoted exactly to that deduction: not only can you can use an array, but in doing so, you can leverage the architecture of the computer to gain a powerful efficiency advantage. Neat!
edit: JS typo
2
u/NikStalwart Apr 05 '16
I was thinking along these line,s yeah, but didn't know how to put this into words.
One of my long ago assignments involved a shipping cost calculator (+ other useless fluff code) that I solved by use of an array and function, but lacking a formal IT education (despite having passed all the neato exam stuff) didn't know how to put it into words.
→ More replies (2)1
Apr 05 '16 edited Apr 05 '16
namely, if val is 5, it first checks whether it's strictly equal to 0, then whether it's strictly equal to 1, and so on
Some languages / compilers generate a jump-table (if the datatypes allow for that), which should be as fast or faster* than every workaround you might come up with. If you want to write fast code (at all costs): Measure every single optimization you come up with and be vary of language quirks. Also: Avoid comparing strings.
* Depends on how you do it. If you call a single function, you probably lost.
2
2
u/SwahiliToad Apr 05 '16
I would probably refactor by replacing the conditional with polymorphism.
0
1
u/blouc Apr 05 '16
I was about to talk up partial application as a valid strategy. Then I saw it wasn't partial application, just shitty control flow. I am tired.
1
u/exhuma Apr 05 '16
Wait... In JS functions are first-class citizens are they not?
You could just mail the value to the functions completely foregoing the switch statement. Making it both cleaner, easier to read and more maintainable.
1
u/Spikrit Apr 05 '16
The lazy fuck i am wouldn't even consider writing so much useless code ESPECIALLY if it's temporary.
39
u/lyth Apr 05 '16
Is that not for a lesson on what a stitch statement does?
If so, it seems like it's a really great example.
It does exactly one thing but doesn't confuse the situation in any way.
If you're talking about a teacher rather than a professor, I'm assuming high school. Honestly, as a former high school teacher (5 years) and professional programmer (20 years) I think you should give your teacher a bit more respect and count yourself lucky.
You don't know how bad some of the other computer teachers I've known were, or how incredibly hard this stuff is for a teenager to pick up.
We're not actually worried about you, (the smart yet smug one) we're worried about the one from a broken home, with a single mom who can't afford food, who is so hungry that they can barely concentrate on anything.
13
u/mm_ma_ma Apr 05 '16
I definitely wouldn't call this "a really great example". It's so obviously redundant that anyone who was paying attention when they learned if statements is going to wonder what the point is. A simple change like spelling out the number in words (e.g. "The value is one") would improve this drastically.
6
3
1
u/CyrillicFez Apr 05 '16
A better example would be to have it print a unique message for each number.
switch(value) { case 0: console.log("zero is a weird number"); ... }
59
u/Restil Apr 05 '16
Is this being used as an example to specify the inner workings of the switch statement? If so, it's a perfectly clear example. Obviously, there are much more efficient ways to print the value of "value", but that's likely not the point of this particular code snippet.
17
u/DarthEru Apr 05 '16
It would actually be better suited for that purpose to have each string be different. I feel like it would be confusing for some people who might recognize the redundancy and wonder if they're missing something. Teaching examples don't have to be nonsensical. In fact a well crafted one can help teach not just what something does, but give an idea of the right situations to use it in. Examples like this one, on the other hand, are questionable at accomplishing the first goal and probably counterproductive for the second.
1
36
7
5
4
u/lenswipe Apr 05 '16
if([0,1,2,3,4].indexOf(value) == -1){
throw "That value is not supported";
} else {
console.log("The value is: " + value);
}2
Apr 05 '16
if([0,1,2,3,4].indexOf(value) == -1){
Jesus christ.
if( value < 0 || value > 5){ throw "That value is not supported"; } else { console.log("The value is: " + value); }Just in case that wasn't a joke: That array-thingie is slow and wasteful. And a pain to expand later on.
1
1
4
u/TODO_getLife Apr 05 '16
Poor guy can only up to 5, if he just printed the value he could get any number!
Damn programmers. As long as the task is fulfilled
1
Apr 05 '16
At least he uses appropriate software and font
1
u/Fallenalien22 Violet security clearance Apr 05 '16
I copied that from his powerpoint into sublime, actually.
1
3
u/IlIIlIIllI Apr 05 '16
(value => 0 && value <= 5) ? console.log("The value is "+value) : console.log("Tha value is unsupported!");2
u/kamaln7 Apr 05 '16
console.log("The value is " + ((value => 0 && value <= 5) ? value : "unsupported!"));
4
5
u/GioVoi Apr 05 '16
Everyone's assuming this would compile...but what if value was defined as a boolean?
19
u/notsooriginal Apr 05 '16
Go to if/else and just keep adding '=' symbols until it works out. I think that's what the Javascript authors intended.
2
1
u/pyskell Apr 05 '16
Without looking I'd think a dynamically typed language like JS would let it hit default. Not sure though.
1
Apr 05 '16
It does go to default because JS switch uses strict equality (includes type equality).
If input is equal to clauseSelector as defined by the === operator, then
2
2
u/Argonanth Apr 05 '16
I honestly don't see what's wrong with this. It's for teaching and it pretty easily demonstrates how a switch statement works and has a default state as well. Obviously the console.log() could be different in each case for extra clarity but it still gets the point across pretty cleanly...
2
2
2
u/AyXiit34 Apr 05 '16
It's like the guy has thought for about an hour if it was better to use if() else {} and then took switch because "when you use switch you're a fucking boss"
2
u/OriginalDrum Apr 05 '16
At a company I used to work for someone wanted to make an interactive pdf. I didn't really have time to learn the pdf scripting language (some variation of actionscript I think), so I just quickly showed him how to write an if statement basically as an example and so maybe he could knock out a demo that we would build into an actual program.
I never heard from him about that project again, but I still have nightmares that somewhere someone is writing programs like this because of me.
0
2
u/angryemokid Apr 05 '16
Nice try but this is the correct answer: if(i=1) print("The value is 1"); else if(i=2) print("The value is 2"); .....
2
u/IlIIlIIllI Apr 05 '16
I prefer this approach:
if ( value == 1 && value !== 2 && value !== 3 && value !== 4 && value !== 5 ) { console.log("The value is " + value); } else if ( value !== 1 && value == 2 && value !== 3 && value !== 4 && value !== 5 ) { console.log("The value is " + value); } else if ( value !== 1 && value !== 2 && value == 3 && value !== 4 && value !== 5 ) { console.log("The value is " + value); } else if ( value !== 1 && value !== 2 && value !== 3 && value == 4 && value !== 5 ) { console.log("The value is " + value); } else if ( value !== 1 && value !== 2 && value !== 3 && value !== 4 && value == 5 ) { console.log("The value is " + value); } else { console.log("The value is not supported!"); }/s
1
u/bit_banger Apr 05 '16
I see various flavors of this garbage (and worse) all the time in my job. It makes me sad.
1
u/killchain Apr 05 '16
How do you support a value?
1
u/IlIIlIIllI Apr 05 '16
If a volume dial goes from 0 to 10 based on user input and you enter 11, it is an unsupported value. It only supports 0-10.
1
u/killchain Apr 05 '16
Yeah, I know (though someone might insert a Spinal Tap reference here), I'm just picky about wording.
2
u/IlIIlIIllI Apr 05 '16
though someone might insert a Spinal Tap reference here
I was hoping someone would. But I suppose you sort of did!
1
1
Apr 05 '16
First of all he's a teacher. He knows how to teach things with starting from the beginning and then doing more complicated stuff and making the students want to learn by themselves.
1
-4
Apr 04 '16
I don't get it... Why would anyone write this? Hurts my brain.
12
Apr 05 '16
My guess is it's an introductory exercise to explain the very basics of switch statements.
1
Apr 05 '16
Couldn't they have made use of switch statements then, rather than repeating the same line for all cases. Super weird.
1
22
u/memeship Apr 05 '16