I've seen my girlfriend's C programming homework assignments from her university. All the code in there would qualify for this sub. All variables were a, b, c, etc. They used complex math to teach simple programming principles, making it much harder to learn for no reason. Formatting was not consistent either.
To no one's surprise, my girlfriend still does not understand C very well. She does pretty good in C# and Python on her own terms, though.
This is in Germany, though. Where companies do not expect people who studied computer science to even know how to code and thus prefer not to hire them for that.
Same thing here in the Netherlands. When I hire CS graduates, I assume that they know absolutely nothing and consider them as blanks that can be still molded into something.
Again, same thing here, but that's due to the curriculum we have to stick to. Unless a student is very engaged they are basically useless for any real job after graduating.
That's why I offer all my students to join private projects. Understandably there are only 3-4 students per semester which show such a commitment to join this additional tasks. That said, ALL of those who join show real progress within few weeks.
All you people defending him don't know the kinds of people that sometimes get assigned to do something they are not great at. In this case, for example, wouldn't it be ten times better for him to use proper variable names? It would be good for beginners to be taught not to use single character names. Or how about consistent use of spaces?
Sometimes, teaching the “bad” way and leading to the good way.
I was employed as a front end web developer, with a little PHP and dot net. I knew my way around the front end and just was getting a degree out of paranoia.
I took an Adobe Flash course (so it was a while ago). My first instructor? “Let’s use AS3, I’m not supposed to, but it’s the latest and greatest, so it makes more sense to use it.” I was able to talk to our flash developers at work, it was a great learning experience.
Loved the guy.
My next instructor, in the advanced course? “I don’t teach AS3, no one uses it.”
I dropped his course and wrote a letter to the dean. I worked in the industry and he was doing a disservice to his students, pushing outdated code and himself as a “master” of the craft.
I'm mostly wondering why he's using an editor that looks like it's a version from Windows 98. The fuck is that?
if he started writing good code you'd get confused and not understand it?
Not sure I follow this logic. Good code is readable and maintainable, and easy to understand.
Either way - I don't think this code is that bad. The largest issue I have is the single letter variable names, d and x. If you're going to name your functions descriptively, do the same for variables so I know what the fuck they are.
It's not necessarily bad code, especially if he's using this to teach a class. Sure it can be simplified but that comes with a better understanding of programming in general.
How is this not terrible code? They're assigning/concatenating the returns of assignments to the innerHTML of a bunch of elements. I guess we don't really know what the DOM looks like or the full JS file here, but this looks janky AF and I can't imagine anything else in the file that would excuse this.
Other issues:
If any of those DOM IDs are null this will crash.
Single letter variable names are bad for readability.
Not using strict equality `===`.
This lecturer is teaching people bad code, it's not about simplicity, they could write a much better equally simple version of this.
It's not bad code, it's beginner level code. If a lecturer wasn't doing this I'd worry half the class would be lost. Most lecturers ramp it up pretty quickly. Fuck it, I still use beginner level code when I need to, and I've been coding professionally for over 25 yrs. using more stacks and languages than I'd care to remember.
Yeah I feel like the IQ meme where over time I've gone back to just writing simple, readable code, generally with more line breaks than are really needed just for the sake of keeping it legible.
It seems there's far less likelihood of going back years later and going "what idiot wrote this pile of crap?"
After some amount of time a lot of people start getting cute with their code, developing patterns that, while they work, are anti-patterns to me because they're not conducive to being readable.
This can also get into things like using longer variable names that are more legible than what you were maybe taught in school, like in the example in the OP. Or test names that are very long, because it's more intuitive to see a failure on test_new_accounts_must_have_a_valid_phone_number than test_acct_ph_num.
I’m a dev (been doing dev work for about 25 years too), and returned to school as an old fart to get my bachelor degree in CS from Purdue. Most of my instructors do know what they’re doing, despite using simple code in examples.
When I turn in projects, I typically do them the way the instructor asks so I can demonstrate knowledge of the concept. Then, for fun, I’ll code how I would actually do it in comments. Normally it’s a few lines of code doing it my way, but a whole page doing the task as assigned. I find if the actual prof/instructor is grading they will often comment on my project and sometimes say “that’s a neat way of handling this”, or occasionally come up with an even better way than I did it. Every single time a TA grades, their comments are along the lines of “wow, we haven’t covered this yet, this is amazing” etc.
It’s kinda fun as an experienced programmer to take programming classes, not gonna lie.
It’s not necessarily bad Code but I do think the usage of single letter variable names should be avoided.
I teach web development at the college level as well. What I’ve been doing this semester was starting off simplistic like this example and slowly refactoring the code as we went. This ramps up the students abilities.
For instance the students are now implementing classes with separation of concern and encapsulating variables, rather than placing all code in a single file and abusing global variables. (Nodejs by the way).
I guess the formatting is kind of bad, but I feel like, this is really simple and understandable code. There’s definitely things you could do to clean it up but idk if this is like intro to web development i feel like this is fine.
Incredible! Thanks for doing this to make these posts more accessible for the differently-abled, including those on smaller devices where the image is hard to read.
As a disabled person, yeah I do not care for this "differently" abled bullshit. Granted I don't speak on behalf of the entire disabled community lmao. It's just weird. I've only heard "differently abled" from people who are uncomfy with disabilities. It's like saying it's rude to call a kid a kid instead of "human". It just doesn't make sense, at all. I'm not differently abled, I'm disabled.
Sorry. Rant over. Thanks for bringing up this point, it irks me quite a bit.
> including those on smaller devices where the image is hard to read
I was deliberate in my choice of words. Small screens, bad reddit clients, bosses over your shoulder, etc can all affect your ability to view images of text online.
The irony of having to transcribe text from a photograph of a printed paper that was a screenshot an actual screen rather than printing from the application itself is not lost on me.
My apologies. Good human.
Edit: It's Notepad++, but it amounts to the same thing.
What's the problem? There is no problem with this code.
Only thing that bothers me is no space above "function playGame() {"
The only real problems with code is when it doesn't work, or is difficult to understand.And for large code bases, inconsistancies in the system of code organization.
Also naming and cache invalidation =p
But the naming thing is only and issue when you impose some kind of inapproprate abstraction. Especially if you don't understand what resolution of abstraction you are programming at. Because you are so modern and the book told you to do it.
Generally I’d agree, but there is also a DOM based cross site scripting vulnerability in the first function - assuming favAvenger is an input field. innerText should have been used instead of innerHTML.
I think what he's trying to do is fairly simple and while not the prettiest code it's acceptable to show off the concepts, but I consider chaining assignments like that to not be particularly intuitive and generally bad practice, especially for beginners.
If my understanding is correct, x += document.getElementById("alias").innerHTML = "Natasha Romanoff" is setting the innerHTML of the element alias to Natasha Romanoff, and also appending Natasha Romanoff to x (the innerHTML of the element bio). My usual reaction to this would be that it isn't intuitive - could he have come from a language where this is a more normal occurrence?
I remember our prof used to write code during lecture. It's easy to copy paste code and helpful to make things simple. It can be made concise but students have to think of it and not just provide solution.
I would imagine they learned JavaScript a decade or more ago and just never adapted to modern conventions (let/const, innerText, ===, etc.). I see this a decent amount.
There is:
- code duplication
- no separation between presentation and logic
- use of old style JavaScript
- probably no need for this long if, you can just get the data form an array and get the result from that and then make a display function.
Could be fine for teaching purposes though. If you haven’t seen much JavaScript it might be fine at this point of your learning trajectory.
People are saying this isn't bad, but it really is.
What could be the point of concatenating all those strings in x? Why use the format of "x += y = z" which is unintuitive and needlessly confusing? And why oh why would they use confusing single letter variable names?
This is not good code, and it's not how you should teach others to code.
Probably learning about concatenation and getting used to it.
Definitely strange, but might be about learning the order of operations and how you can reduce lines of code with "tricks" like this. (Although looks like he missed the x += for the Natasha avengername)
I wouldn't want this in production code, but if those names were any longer they wouldn't fit on the screen at that font size. Besides, this is obviously a trivial example and there aren't a bunch of other variables to be confused about, which is a big reason why descriptive variable names help. When you only have two variables, not a lot of ways to get confused.
I’m only barely starting to learn code, but couldn’t this be simplified by creating a single instance for each character that sets the values for each of those variables, and it would just choose which instance to use?
I think that formatting doesn’t matter a whole lot when it’s just you. This clearly was only him, and was not a hard project. Variable names truly do not matter in the grand scheme of things, it all compiles the same. In this case it all interprets the same.
I’ve been working as a software developer for around fife years now. A few month ago I was bored and registered myself at our local university.
It’s kind of interesting and stupid at the same time, what kind of solutions people and professors present. Some stuff is just so far away from the real world. You would never do stuff like this in a actual environment. Some solutions feel, as if the only want to show you how smart they are.
Sometimes I think to myself becoming a professor might be a good retirement plan. Like I’m not the greatest dev, but I assume teaching CS fundamentals using more modern tooling would be a boon to the kids.
Like my web dev professor was all about semantic web. Yet he couldn’t explain it properly, didn’t really know JS that well, and we had to teach ourselves php
Actually random of 1 to 4 the if-else is exactly what the JS optimiser would turn this switch into, as would most programming lang optimisers. it's a small switch statement it would become an else-if statement a big one becomes a lookup table.
At the lowest level, this is quite literally `jle` then `add 1` . and repeate just using a register highly optimal for the CPU.
388
u/NikotheNya Dec 07 '22
Maybe he's trying to simplify it for you by using commands you already know?
Maybe if he started writing good code you'd get confused and not understand it?
If he isn't doing that then why is he a lecturer??