this post was submitted on 24 Mar 2024
788 points (98.6% liked)

Programmer Humor

19585 readers
508 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
 
(page 3) 34 comments
sorted by: hot top controversial new old
[–] [email protected] 11 points 7 months ago (4 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] 19 points 7 months 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)
[–] [email protected] 29 points 7 months ago (2 children)

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

[–] [email protected] 11 points 7 months ago

That seems to be the consensus.

load more comments (1 replies)
[–] [email protected] 106 points 7 months 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] 15 points 7 months ago

Oh wow. Thanks

load more comments (13 replies)
[–] [email protected] 177 points 7 months ago (5 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.

load more comments (5 replies)
[–] [email protected] 29 points 7 months ago* (last edited 7 months ago) (4 children)

Trick question?

attribute error

[–] [email protected] 14 points 7 months ago (1 children)
[–] [email protected] 8 points 7 months ago (1 children)

I am currently looking for job opportunity and amount of gotcha type question i see in OA is just something else.

[–] [email protected] 8 points 7 months ago (1 children)

I can’t imagine that’s any fun to deal with.

“You should have known what the intent of the question was. Management won’t know or care about the internals of your code as long as it meets requirements. You have failed this test.”

Or

“You should know that you’re calling a function with invalid parameters. Where did you get your CS degree from again?”

[–] [email protected] 8 points 7 months ago* (last edited 7 months ago)

“You should have known what the intent of the question was. Management won’t know or care about the internals of your code as long as it meets requirements. You have failed this test.”

“You should know that you’re calling a function with invalid parameters. Where did you get your CS degree from again?”

sigh you can have your ransom, just remove the cameras.

load more comments (3 replies)
[–] [email protected] 56 points 7 months ago* (last edited 7 months ago) (12 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] 2 points 7 months ago (2 children)

Why not Python? Because it needs print(str(x))?

load more comments (2 replies)
[–] [email protected] 10 points 7 months ago (1 children)

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

[–] [email protected] -3 points 7 months ago (1 children)

It's a shitty question. It's implied by the fact that "24" is wrong that the answer is "6", the length of the string "Monday".

In some languages dot access on objects could give you the properties of the object type (things pertaining to a "day" object) but this would still be ambiguous since a day's length can be measured in many different ways.

In others, it would require you to call length as a function (.length()) or not be available at all, or require you to pass the object into another function [ length_in_seconds(day_x)]

load more comments (1 replies)
[–] [email protected] 46 points 7 months 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 7 months ago (1 children)

Especially since python is right there.

[–] [email protected] 6 points 7 months 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] 1 points 7 months ago
load more comments (6 replies)
load more comments (2 replies)
[–] [email protected] 88 points 7 months ago (4 children)

OCR exam language, a pseudocode format.

load more comments (4 replies)
[–] [email protected] 2 points 7 months ago* (last edited 7 months ago)

Same thoughts I had.

  1. Language which allows variable declaration as name = value without any keywords or its a variable declared outside of the example
  2. Has lowercase .length and not .len or other
  3. .length is also a property and not a method? Assuming convention .length() for method call like print(x)
[–] [email protected] 10 points 7 months ago* (last edited 7 months ago) (2 children)

That recurring puzzle is among the most interesting aspects of this community, IMHO.

[–] [email protected] 8 points 7 months ago

It’s weird that people are so focused on it. It’s pseudocode, and it’s purely meant for day one comp sci students to grasp how data is stored and processed, before they are forced into writing Java, most likely

[–] [email protected] 5 points 7 months ago (1 children)

Most irritating aspect of switching languages. How are switches done in this one again?

•Searches web•

Ah yes

load more comments (1 replies)
[–] [email protected] 17 points 7 months ago (1 children)
[–] [email protected] 8 points 7 months ago (3 children)

doesnt have print nor allow variable declaration without keywords

[–] [email protected] 5 points 7 months ago

Sure you can write foo = 3 in JavaScript. It’s a global variable and can be referenced as either foo or window.foo.

[–] [email protected] 25 points 7 months 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.

[–] [email protected] 8 points 7 months ago

it's so rough learning this by accident

[–] [email protected] 12 points 7 months ago* (last edited 7 months 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.

[–] [email protected] 9 points 7 months ago* (last edited 7 months ago)

JavaScript is the language of the assassins, with its infinitely modifiable prototypical setup

Nothing is true

true !== 1

true

true + true + true === 3

true

Everything is permitted

[]+[]

''

load more comments (5 replies)
[–] [email protected] 12 points 7 months ago* (last edited 7 months ago)

does it give reference to what language this is in?

x = string length of “Monday” => 6

passed my gcse?

load more comments
view more: ‹ prev next ›