787
Exam Answer (programming.dev)
top 50 comments
sorted by: hot top controversial new old
[-] lthlnkso@programming.dev 178 points 8 months ago

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.

[-] agressivelyPassive@feddit.de 51 points 8 months ago

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.

[-] captain_aggravated@sh.itjust.works 22 points 8 months ago

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)
[-] MrRazamataz@lemmy.razbot.xyz 29 points 8 months 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)
[-] treechicken@lemmy.world 143 points 8 months ago

It's obviously:

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

[-] theFibonacciEffect@feddit.de 32 points 8 months ago

Ah yes, all pseudocode is python

[-] SkyeHarith@lemmy.world 29 points 8 months ago

Ah yes, python is psuedocode

load more comments (1 replies)
[-] vvvvv@lemmy.world 99 points 8 months ago

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

[-] smokeybeef@lemm.ee 20 points 8 months ago* (last edited 8 months ago)

screw your students

ಠ_ಠ

load more comments (1 replies)
[-] silasmariner@programming.dev 83 points 8 months ago* (last edited 8 months ago)

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)

[-] Magnetar@feddit.de 24 points 8 months ago
load more comments (4 replies)
[-] paholg@lemm.ee 21 points 8 months ago

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)
[-] PhAzE@lemmy.ca 63 points 8 months ago* (last edited 8 months ago)

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

load more comments (13 replies)
[-] dragontamer@lemmy.world 57 points 8 months ago* (last edited 8 months ago)

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.

[-] JackGreenEarth@lemm.ee 88 points 8 months ago

OCR exam language, a pseudocode format.

[-] kn0wmad1c@programming.dev 10 points 8 months ago

This could run in Javascript if you setup print as an alias for window.alert or console.log

load more comments (3 replies)
[-] Minotaur@lemm.ee 46 points 8 months ago

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

[-] nxdefiant@startrek.website 22 points 8 months ago

Especially since python is right there.

load more comments (8 replies)
load more comments (2 replies)
[-] CanadaPlus@lemmy.sdf.org 28 points 8 months ago

Just pseudocode.

[-] lugal@lemmy.ml 10 points 8 months ago

This is quite a cheap answer but maybe it's just pseudo code. We had exercises in university about pseudo code with examples that intentionally broke all syntax systems and conventions to show that not everything has to be executable that you write down in a theoretical computer science homework

load more comments (2 replies)
[-] NeatNit@discuss.tchncs.de 10 points 8 months ago

My headcanon: it's a language that gets executed by a LLM. Whatever you write, if the LLM can make sense of it, it will execute it.

The output may well be "24 hours".

load more comments (11 replies)
[-] SquishyPandaDev@yiffit.net 35 points 8 months ago* (last edited 8 months ago)

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

[-] qaz@lemmy.world 11 points 8 months ago

But does it count the null byte or not?

load more comments (1 replies)
[-] Miaou@jlai.lu 35 points 8 months ago

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.

[-] OR3X@lemm.ee 14 points 8 months ago

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

load more comments (5 replies)
[-] alexdeathway@programming.dev 29 points 8 months ago* (last edited 8 months ago)

Trick question?

attribute error

[-] Car@lemmy.dbzer0.com 14 points 8 months ago
load more comments (3 replies)
load more comments (3 replies)
[-] jlow@beehaw.org 19 points 8 months ago

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)
[-] breadsmasher@lemmy.world 12 points 8 months ago* (last edited 8 months ago)

does it give reference to what language this is in?

x = string length of “Monday” => 6

passed my gcse?

[-] stoly@lemmy.world 11 points 8 months ago

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?

[-] Akrenion@programming.dev 106 points 8 months ago

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

[-] stoly@lemmy.world 15 points 8 months ago

Oh wow. Thanks

load more comments (13 replies)
[-] Car@lemmy.dbzer0.com 29 points 8 months ago

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

[-] stoly@lemmy.world 11 points 8 months ago

That seems to be the consensus.

load more comments (1 replies)
[-] CrazyEddie041@kbin.social 19 points 8 months ago

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)
[-] ChaoticNeutralCzech@feddit.de 11 points 8 months ago
load more comments
view more: next ›
this post was submitted on 24 Mar 2024
787 points (98.6% liked)

Programmer Humor

19623 readers
1 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 1 year ago
MODERATORS