this post was submitted on 24 Mar 2024
785 points (100.0% liked)

Programmer Humor

23119 readers
787 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS
 
top 50 comments
sorted by: hot top controversial new old
[–] [email protected] 179 points 1 year ago (3 children)

I think this is a good question and answer in the sense that it reveals a fundamental misunderstanding on the part of the student - exactly what you hope an exam would do! (Except for how this seems to combine javascript's .length and python's print statement - maybe there is a language like this though - or 'print' was a javascript function defined elsewhere).

This reminds me once of when I was a TA in a computer science course in the computer lab. Students were working on a "connect 4" game - drop a token in a column, try to connect 4. A student asked me, while writing the drop function, if he would have to write code to ensure that the token "fell" to bottom of the board, or if the computer would understand what it was trying to do. Excellent question! Because the question connects to a huge misunderstanding that the answer has a chance to correct.

[–] [email protected] 54 points 1 year ago (1 children)

Teaching complete "clean slates" is a great way to re-evaluate your understanding.

I've had to teach a few apprentices and while they were perfectly reasonable and bright people, they had absolutely no idea, how computers worked internally. It's really hard to put yourself in the shoes of such persons if it's been too long since you were at this point of ignorance.

[–] [email protected] 22 points 1 year ago (1 children)

I forget which one, but one of my flight instructor textbooks said "to teach is to learn twice." And BOY HOWDY is that accurate.

You will find no better teacher of expert aeronautics than a brand new student. They will show you a new perspective, every single time.

load more comments (1 replies)
[–] [email protected] 28 points 1 year ago

For reference the "language" used in the exam would probably be Exam Reference Language (OCR exam board specifically, which I believe this question is from) which is just fancier pseudocode.

load more comments (1 replies)
[–] [email protected] 142 points 1 year ago (1 children)

It's obviously:

Traceback (most recent call last): File "./main.py", line 2, in AttributeError: 'str' object has no attribute 'length'

[–] [email protected] 32 points 1 year ago (1 children)

Ah yes, all pseudocode is python

[–] [email protected] 29 points 1 year ago (1 children)

Ah yes, python is psuedocode

load more comments (1 replies)
[–] [email protected] 99 points 1 year ago (1 children)

print("x") is you want to screw your students.

[–] [email protected] 20 points 1 year ago* (last edited 1 year ago) (1 children)

screw your students

ಠ_ಠ

load more comments (1 replies)
[–] [email protected] 83 points 1 year ago* (last edited 1 year ago) (2 children)

They missed out the context code:

trait DoW { def length: FiniteDuration }
object Monday extends DoW { override def length = 24.hours }
...
implicit def toDoW(s: String): DoW = s match {
 case "Monday" => Monday
...
}
var day: DoW = _

(Duration formatting and language identification are left as an exercise for the reader)

[–] [email protected] 24 points 1 year ago (4 children)
load more comments (4 replies)
[–] [email protected] 21 points 1 year ago (1 children)

Works even better in Ruby, as the code as given is valid, you just need to monkey patch length:

#!/usr/bin/env ruby

module DayLength
  def length
    if ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"].include? self
      "24 hours"
    else
      super
    end
  end
end

class String
  prepend DayLength
end

day = "Monday"

x = day.length

print(x)
load more comments (1 replies)
[–] [email protected] 67 points 1 year ago* (last edited 1 year ago) (1 children)

The answer is 6. It's 6 characters long.

[–] [email protected] 22 points 1 year ago (4 children)

Not really, no. That would be the answer if x= len(day). The code in the image would just throw an error.

[–] [email protected] 63 points 1 year ago

Yea, it's pseudo code.

[–] [email protected] 25 points 1 year ago (3 children)

"Monday".length is working JavaScript and does equal 6. No print command afaik though.

[–] [email protected] 12 points 1 year ago (1 children)
load more comments (1 replies)
load more comments (2 replies)
[–] [email protected] 12 points 1 year ago* (last edited 1 year ago) (3 children)

no it wouldn't, because this is OCR reference language

run this

load more comments (3 replies)
load more comments (1 replies)
[–] [email protected] 55 points 1 year ago* (last edited 1 year ago) (19 children)

Is it wrong that I'm stuck trying to figure out what language this is?

Trying to figure out what string.length and print(var) exist in a single language.... Not Java, not C# (I'm pretty sure its .Length, not length), certainly not C, C++ or Python, Pascal, Schme or Haskell or Javascript or PHP.

[–] [email protected] 85 points 1 year ago (4 children)

OCR exam language, a pseudocode format.

load more comments (4 replies)
[–] [email protected] 46 points 1 year ago (3 children)

I’m very much guessing that this is just supposed to be a type of pseudocode given the context and vagueness of it.

It’s a big reason why I really dont like pseudocode as instruction to people learning the basics of what programming is. It made more sense 20 years ago when programming languages were on a whole a lot more esoteric and less plain text, but now with simple languages like Python there’s simply little reason to not just write Python code or whatever.

I took an intro to programming class in College and the single thing I got dinged on the most is “incorrect pseudocode”, which was either too formal and close to real code or too casual and close to plain English.

It’s not a great system. We really need to get rid of it as a practice

[–] [email protected] 22 points 1 year ago (1 children)

Especially since python is right there.

[–] [email protected] 12 points 1 year ago (7 children)

I mean once you get beyond bash-like scripts python is esoteric as fuck, adding oop to what is essentially a shell is a terrible idea

That said, there's plenty of languages with good syntax that is still good when you get into more complex stuff (modern C#, scala, kotlin and more)

[–] [email protected] 11 points 1 year ago

The only thing esoteric about python is the bolted-on typing and anything behind a double underscore.

So yeah, it's there, but in front of the curtain it's practically pseudo code.

load more comments (6 replies)
load more comments (2 replies)
[–] [email protected] 27 points 1 year ago

Just pseudocode.

[–] [email protected] 16 points 1 year ago (1 children)
[–] [email protected] 11 points 1 year ago (3 children)

doesnt have print nor allow variable declaration without keywords

[–] [email protected] 25 points 1 year ago (1 children)

print() will print the text to a physical printer with paper and everything. Don't confuse it with console.log and use it in a loop.

load more comments (1 replies)
[–] [email protected] 12 points 1 year ago* (last edited 1 year ago) (1 children)

It would have print if it was previously declared as function.

Also, js is as dirty as you want it to be. Keywords are indeed not necessary for declaring variables.

load more comments (1 replies)
load more comments (1 replies)
load more comments (15 replies)
[–] [email protected] 39 points 1 year ago (6 children)

The amount of people nitpicking about the brand of pseudocode or arguing the question is tricky reminds me of some coworkers, and not the good kind.

If you belong to the above category, try to learn some new programming language / read about some algorithm descriptions (not implementation) and go out take some sun. The question is super intuitive if you're not stuck to a single paradigm or language.

[–] [email protected] 15 points 1 year ago

Exactly. It's pseudo code. It's meant to be universally understandable, not language specific.

load more comments (5 replies)
[–] [email protected] 36 points 1 year ago* (last edited 1 year ago) (3 children)

Good thing this only uses ASCii characters, else you get into some fun discussions about UTF encoding

load more comments (3 replies)
[–] [email protected] 31 points 1 year ago* (last edited 1 year ago) (4 children)

Trick question?

attribute error

[–] [email protected] 19 points 1 year ago (3 children)
load more comments (3 replies)
load more comments (3 replies)
[–] [email protected] 19 points 1 year ago (8 children)

I wonder if day length is given separately in a table prior to the question? I’m not sure what they wanted except maybe seconds?

[–] [email protected] 105 points 1 year ago (14 children)

It's the length of the string. The number of characters is 6. It's a play on words and a question.

[–] [email protected] 14 points 1 year ago

Oh wow. Thanks

load more comments (13 replies)
[–] [email protected] 29 points 1 year ago (2 children)

I’m assuming they wanted the literal length of the string

[–] [email protected] 11 points 1 year ago

That seems to be the consensus.

load more comments (1 replies)
[–] [email protected] 19 points 1 year ago (4 children)

Conversations about language aside, the error is that "Monday" is a string with a length of 6.

load more comments (4 replies)
load more comments (5 replies)
[–] [email protected] 19 points 1 year ago (2 children)

Are they using a red pen to write the checkmarks for correct answers to make it confusing but logical at least?

load more comments (2 replies)
[–] [email protected] 12 points 1 year ago* (last edited 1 year ago)

does it give reference to what language this is in?

x = string length of “Monday” => 6

passed my gcse?

[–] [email protected] 11 points 1 year ago
load more comments
view more: next ›