There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

programmer_humor

This magazine is from a federated server and may be incomplete. Browse more on the original instance.

lthlnkso , in Exam Answer

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 ,

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 ,
@captain_aggravated@sh.itjust.works avatar

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.

abbadon420 ,

Second this. I’m a teacher aid and I get to fix student’s code for students who are not technically inclined. It’s so much fun and I’ve learned so much McGuivering all that shitty mess together.

MrRazamataz ,
@MrRazamataz@lemmy.razbot.xyz avatar

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.

morrowind ,
@morrowind@lemmy.ml avatar

To add on to exam reference languages, this is valid ruby

stoly , in Exam Answer

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 ,

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

stoly ,

Oh wow. Thanks

r00ty Admin ,
r00ty avatar

I'm not really a fan of this kind of question. Especially if there's enough questions that time will be an issue for most. Because at first glance it's easy to think the answer might be the length of a day.

There shouldn't be a need to try to trick people into the wrong answer on an open question. Maybe with multiple choice but not an open answer question.

CanadaPlus ,

It relies on critical thinking (meaning thinking about your own thinking), basically, and most students aren’t very good at that.

Couldbealeotard ,
@Couldbealeotard@lemmy.world avatar

This doesn’t rely on critical thinking. It just relies on understanding what “.length” does, which would’ve been previously covered in the lessons.

CanadaPlus , (edited )

Well, both. If you rushed through without recalling that length has specific meaning relative to strings, even though you do know that, that’s a critical thinking failure. But yeah, not knowing strings could do it too.

Couldbealeotard ,
@Couldbealeotard@lemmy.world avatar

If you didn’t know the answer, it’s a critical thinking exercise? Not at all.

Answering this question relies completely on understanding programming. A correct answer cannot be reached without an understanding of programming.

CanadaPlus , (edited )

A correct answer cannot be reached without an understanding of programming.

Yes. It does not follow, though, that knowledge of programming always leads to a correct answer. Since you seem like someone who might appreciate a formal logical description, you are affirming the consequent here.

Again, without sufficient critical thinking one might just miss the detail that “Monday” is a string and not a custom unit-of-time object, inheriting from Day.

Couldbealeotard ,
@Couldbealeotard@lemmy.world avatar

But you can only mistake it as a custom object of you understand how coding works. I’m not saying an understanding will prevent you from being wrong, I’m saying having critical thinking will not reach the answer if you don’t have an understanding.

AdlachGyfiawn ,
@AdlachGyfiawn@lemmygrad.ml avatar

Software engineering as a discipline is pretty much a series of trick questions.

RagingRobot ,

I get your point about it being a trick question but I think in this case it’s pretty reasonable that you would see code like this in real life. Where the programming metaphor and your understanding of the real world clash. It’s a very important skill to be able to spot the difference.

onlinepersona ,

The compiler or interpreter does that for you. There’s no point in these “gotcha’s”. They are cute brain teasers that belong on those useless “are you a programmer” quizzes you find on random meme websites, not an exam.

CC BY-NC-SA 4.0

RagingRobot ,

In the error shown a compiler would be just fine and run as usual but the person programming it would be expecting a different result so a compiler wouldn’t do this for you since it’s a logical error and not a syntax error.

onlinepersona ,

If it’s a statically typed language and x is of type Date, it’s for sure throw a type error when trying to assign a string to it. If it had autoboxing / auto type conversion from String to Date, length could return a number or a string.

If this were Javascript on NodeJS, it would fail at print(x) because that doesn’t exist in JS. If it were Python it would fail at x.length because that has to be len(x). And so on.

If this were all to pass, at the latest at runtime, when the programmer sees the output “6”, they would know something’s up.

As I said, cute, but worthless test.

CC BY-NC-SA 4.0

Car ,

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

stoly ,

That seems to be the consensus.

zarkanian ,
@zarkanian@sh.itjust.works avatar

Naw, they wanted the metaphorical length. Computers are great at metaphors.

dog ,

Most date libraries count to 23h 59m 59s then roll over to 00h 00m 00s. So the answer is 23 hours, not 24.

Edit: I’m big dum dum. It’s asking string length of “Monday”, thus 6.

deadbeef79000 ,

You’re also mistaken about the time too. The first second of the day is 00:00:00 the last second of the day is 23:59:59

That’s still a full and exact 24 hours.

dog ,

Yes, it’s a full 24 hours, but a library doesn’t use 24:00:00 to represent the last hour, it’s 23:59:59. Once it hits 24:00, it rolls over to 00:00:00.

Hence my initial error of answering 23.

It’s not valid, but I don’t edit out erronous answers because I believe all data should be preserved, no matter how dumb it makes one look.

diverging ,
@diverging@lemmy.ml avatar

00:00:00 is the 1st second of the day. 23:59:59 is the 86400th second of the day. That’s 24 hours.

deadbeef79000 ,

It’s not valid, but I don’t edit out erronous answers because I believe all data should be preserved, no matter how dumb it makes one look.

Doing the lord’s work.

I have but one up vote and you already have it.

CrazyEddie041 ,
@CrazyEddie041@kbin.social avatar

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

nathanjent ,

What is the type of the variable day though? As it is we have to make multiple assumptions, based on popular programming languages, about the internals of the string type and the print function to assume that it prints “6”.

ripcord ,
@ripcord@lemmy.world avatar

There is a fairly good chance that there has been more info presented in the class than we have been given here.

morrowind ,
@morrowind@lemmy.ml avatar

That’s the variable name, not the type

mox , in Exam Answer

hours = 0.25

There. I fixed it! :)

takeda , (edited ) in Exam Answer

For 1 hour = 4^(-1) characters

cows_are_underrated , in Exam Answer

It is indeed wrong. The correct answer would be 24.

kubica , in Exam Answer
@kubica@kbin.social avatar

The future is not yet young man.

silasmariner , in Exam Answer

They missed out the context code:


<span style="color:#323232;">trait DoW { def length: FiniteDuration }
</span><span style="color:#323232;">object Monday extends DoW { override def length = 24.hours }
</span><span style="color:#323232;">...
</span><span style="color:#323232;">implicit def toDoW(s: String): DoW = s match {
</span><span style="color:#323232;"> case "Monday" => Monday
</span><span style="color:#323232;">...
</span><span style="color:#323232;">}
</span><span style="color:#323232;">var day: DoW = _
</span>

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

Magnetar ,

Upvote for using Scala.

silasmariner ,

Implicit was too much of a give away wasn’t it?

Magnetar ,

I’ve literally seen code that does something awfully similar. But you could have used an Enumeration.

Fuck, I think you just gave me an idea for an issue in my code that has bugged me for days.

silasmariner , (edited )

I could’ve used a lot of things, but I’m on my phone and I wanted fewer characters to render it, whilst being sure it would work without having to run it.

Also, I am pleased to have maybe helped. Perhaps we can be friends, you and I. Perhaps not. Idk, maybe you punch dogs, why would you do that? Seems mean.

Have you ever just, like, edited a comment? How do people know when you did it? I guess if I were writing a thing to check it I’d use a registry of timestamps and checksums… So, like, ok, you can track, but why, how does it look?

Anyway sorry I had some drinks between now and first post, goodnight

paholg ,

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


<span style="color:#323232;">#!/usr/bin/env ruby
</span><span style="color:#323232;">
</span><span style="color:#323232;">module DayLength
</span><span style="color:#323232;">  def length
</span><span style="color:#323232;">    if ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"].include? self
</span><span style="color:#323232;">      "24 hours"
</span><span style="color:#323232;">    else
</span><span style="color:#323232;">      super
</span><span style="color:#323232;">    end
</span><span style="color:#323232;">  end
</span><span style="color:#323232;">end
</span><span style="color:#323232;">
</span><span style="color:#323232;">class String
</span><span style="color:#323232;">  prepend DayLength
</span><span style="color:#323232;">end
</span><span style="color:#323232;">
</span><span style="color:#323232;">day = "Monday"
</span><span style="color:#323232;">
</span><span style="color:#323232;">x = day.length
</span><span style="color:#323232;">
</span><span style="color:#323232;">print(x)
</span>
silasmariner , (edited )

Code as given can be made valid in scala I believe. My starter was based on that assumption. I think raku can do it too, but you would probably have to x = $ to make it work…

Edit: misread your comment slightly, CBA to change mine now. It is what it is

CanadaPlus , (edited ) in Programming languages personified - leftoversalad

This is epic.

Can anyone explain Java, PHP and Perl to me?

xmunk ,

Java is extremely widespread in corporate companies - hence the suit and tie. Perl is fair to liken to spelunking deep into a dark cave with only your wits to save you.

PHP seems to be a reference to the fact that it’s extremely common on servers… but it also might be a lazy phpbad joke - it’s pretty weak either way (if you wanted to play into the server characteristic give it a dozen arms serving the entire restaurant in the background).

frezik ,

As a Perl dev, I dunno if that’s how I’d characterize the language, but I’ll take it over yet another “Perl is unreadable line noise lol and what’s the deal with airline food” reference.

xmunk ,

Yeah, to be honest you can write good code in any language and it’ll usually look pretty similar… all the perl stereotypes come from having to maintain shell scripts from someone kludging their way through learning to code… it’s the same reason why phpbad, amateurs could get into webdev with php so there’s an impression that all php is the php written by amateurs.

Also, bear in mind that over time these languages have converged through feature additions “LISP has functional programming - why can’t PHP have first class functions… oh traits look neat, let’s add that… you know those statically typed languages sure seem nice…”

maniel ,

Guess PHP is a server…

CanadaPlus ,

That seems to be the consensus. That’s pretty weak, salad people, you know you could have done better.

SquishyPandaDev , (edited ) in Exam Answer
@SquishyPandaDev@yiffit.net avatar

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

qaz ,

But does it count the null byte or not?

SquishyPandaDev ,
@SquishyPandaDev@yiffit.net avatar

In most languages, length method doesn’t count the null terminator. Might result in some fun memory errors

YoorWeb ,
jlow , in Exam Answer

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

autokludge ,
@autokludge@programming.dev avatar

Nah, just using one of those handy pens with blue, black & 2 red ink. ;)

blindsight ,

Grading in red is generally avoided, nowadays. Red is closely associated with failure/danger/bad, and feedback should generally be constructive to help students learn and grow.

I usually like to grade in a bright colour that students are unlikely to pick: purple, green, pink, orange, or maybe light blue (if most students are working in pencil). Brown is poo. Black and dark blue are too common. Yellow is illegible. Red is aggressive.

Anyway, I’m guessing they just graded everything in green. The only time I’ve ever graded in more than one colour was when I needed to subgrade different categories of grades, like thinking/communication/knowledge/application. In that case, choosing a consistent colour for each category makes it easier to score.

ChickenLadyLovesLife , in traslation: i made that bug 15 years ago and have been waiting for it to matter.

Not a bug exactly, but about ten years ago I was working as an iOS developer and to get around a major problem introduced by the app designer, I made use of a “private method”, which is something an app supposedly gets rejected for by Apple. I came up with a way of hiding it and had to sweat out the approval period before it went live. Ten years later that shit is still there; I’m sure the developers currently responsible for the app don’t even know it’s there. I normally comment my code with an eye to helping future programmers understand what’s going on and why, but this hack was one where I even obscured the comments.

AVincentInSpace ,

What does “private method” mean in this context? Did you make use of an undocumented endpoint of the iOS API?

ChickenLadyLovesLife ,

Yeah, same thing.

firelizzard ,
@firelizzard@programming.dev avatar

Objective-C does not enforce method access (e.g. private methods) at the runtime level. If you are sufficiently determined, there are no restrictions on what methods you can call, unlike Java or C# (AFAIK).

AVincentInSpace ,

Java absolutely lets you do that with Reflections. You’re not supposed to, and it’s painfully slow, but the JVM is only marginally smarter than javac (and that’s saying something) so there’s nothing actually stopping you.

humbletightband ,

If you are determined enough, it’s not that slow 😉

firelizzard ,
@firelizzard@programming.dev avatar

I thought there was security code to stop that kind of thing. Granted, it’s been over 10 years since I’ve done anything with Java more than tinkering with Minecraft mods.

homura1650 ,

Java did have a Security Manager that can be used to prevent this sort of thing. The original thinking was that the Java runtime would essentially be an OS, and you could have different applets running within the runtime. This required a permission system where you could confine the permissions of parts of a Java program without confining the entire thing; which led to the Java security manager.

Having said that, the Java Security Manager, while an interesting idea, has never been good. The only place it has ever seen significant use was in webapps, where it earned Java the reputation for being insecure. Nowadays, Java webapps are ancient history due to the success of Javascript.

The security manager was depreciated in Java 17, and I believe removed entirely in Java 21.

PhAzE , in Exam Answer

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

potustheplant ,

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

force , (edited )

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

run this

Ephera ,

What the heck, did someone invent a programming language, so students wouldn’t have to learn any real ones?

mounderfod ,
@mounderfod@lemmy.sdf.org avatar

Having done OCR GCSE computing:
It’s just a pseudocode style language that they use in exam questions so that you can understand the question regardless of which language your school had you study (in my case it was VB6 💀). In questions where you are asked to write code, you can use the reference language but realistically you just use the one you learned (although I did it all in python instead)

56_ ,
@56_@lemmy.ml avatar

Huh interesting. In Scotland we had another one: en.wikipedia.org/…/Haggis_(programming_language)

PhAzE ,

Yea, it’s pseudo code.

flumph ,
@flumph@programming.dev avatar

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

AnAngryAlpaca ,

deleted_by_author

  • Loading...
  • kia ,

    You don’t need terminating semicolons in JavaScript. They’re added in if missing. It can actually cause a few bugs around returns.

    dvlsg ,
    @dvlsg@lemmy.world avatar

    There technically is!

    developer.mozilla.org/en-US/docs/Web/API/…/print

    Well. In browsers, anyways.

    Scrollone ,

    Yes, but it prints the page, so in this case it wouldn’t print anything

    PrettyFlyForAFatGuy , (edited )
    
    <span style="color:#323232;">function print(str) {
    </span><span style="color:#323232;">  console.log(str)
    </span><span style="color:#323232;">}
    </span>
    

    FTFY

    fidodo ,

    How do you know what language this is?

    treechicken , in Exam Answer
    @treechicken@lemmy.world avatar

    It’s obviously:

    Traceback (most recent call last): File “./main.py”, line 2, in <module> AttributeError: ‘str’ object has no attribute ‘length’

    theFibonacciEffect ,

    Ah yes, all pseudocode is python

    SkyeHarith ,

    Ah yes, python is psuedocode

    treechicken ,
    @treechicken@lemmy.world avatar

    I deduce these two sets must be the same then?

    vvvvv , in Exam Answer

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

    smokeybeef ,

    screw your students

    ಠ_ಠ

    treechicken ,
    @treechicken@lemmy.world avatar

    “Dr. Prof. Mann, I really didn’t understand anything about UNIX on that last midterm. Can we go over how to touch and finger after class?”

    tatterdemalion , in Programming languages personified - leftoversalad
    @tatterdemalion@programming.dev avatar

    Erlang really is the necromancer’s language.

    Why is Swift… like that?

  • All
  • Subscribed
  • Moderated
  • Favorites
  • [email protected]
  • random
  • lifeLocal
  • goranko
  • All magazines