Beehaw
  • Communities
  • Create Post
  • search
    Search
  • Login
  • Sign Up
JPDev ( JPDev@programming.dev )  to Programmer Humor@programming.dev · 3 years ago

Exam Answer

programming.dev

message-square
33
link
fedilink
456

Exam Answer

programming.dev

JPDev ( JPDev@programming.dev )  to Programmer Humor@programming.dev · 3 years ago
message-square
33
link
fedilink
alert-triangle
You must log in or # to comment.
  • silasmariner ( silasmariner@programming.dev ) 
    link
    fedilink
    arrow-up
    50
    ·
    3 years 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 ( Magnetar@feddit.de ) 
      link
      fedilink
      arrow-up
      16
      ·
      3 years ago

      Upvote for using Scala.

      • silasmariner ( silasmariner@programming.dev ) 
        link
        fedilink
        arrow-up
        7
        ·
        3 years ago

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

        • Magnetar ( Magnetar@feddit.de ) 
          link
          fedilink
          arrow-up
          6
          ·
          3 years ago

          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 ( silasmariner@programming.dev ) 
            link
            fedilink
            arrow-up
            5
            ·
            edit-2
            3 years ago

            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

          • silasmariner ( silasmariner@programming.dev ) 
            link
            fedilink
            arrow-up
            1
            ·
            3 years ago

            deleted by creator

    • paholg ( paholg@lemm.ee ) 
      link
      fedilink
      English
      arrow-up
      14
      ·
      3 years 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)
      
      • silasmariner ( silasmariner@programming.dev ) 
        link
        fedilink
        arrow-up
        4
        ·
        3 years ago

        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

  • lthlnkso ( lthlnkso@programming.dev ) 
    link
    fedilink
    arrow-up
    45
    ·
    3 years 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.

    • AggressivelyPassive ( agressivelyPassive@feddit.de ) 
      link
      fedilink
      arrow-up
      26
      ·
      3 years 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.

    • MrRazamataz ( MrRazamataz@lemmy.razbot.xyz ) 
      link
      fedilink
      English
      arrow-up
      13
      ·
      3 years 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.

    • morrowind ( morrowind@lemmy.ml ) 
      link
      fedilink
      arrow-up
      2
      ·
      3 years ago

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

  • PhAzE ( PhAzE@lemmy.ca ) 
    link
    fedilink
    arrow-up
    36
    ·
    3 years ago

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

    • potustheplant ( potustheplant@feddit.nl ) 
      link
      fedilink
      arrow-up
      14
      ·
      3 years ago

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

      • PhAzE ( PhAzE@lemmy.ca ) 
        link
        fedilink
        arrow-up
        41
        ·
        3 years ago

        Yea, it’s pseudo code.

      • FlumPHP ( flumph@programming.dev ) 
        link
        fedilink
        arrow-up
        18
        ·
        3 years ago

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

        • PrettyFlyForAFatGuy ( PrettyFlyForAFatGuy@feddit.uk ) 
          link
          fedilink
          arrow-up
          4
          ·
          3 years ago
          function print(str) {
            console.log(str)
          }
          

          FTFY

        • AnAngryAlpaca ( AnAngryAlpaca@feddit.de ) 
          link
          fedilink
          arrow-up
          1
          ·
          3 years ago

          deleted by creator

          • kia ( kia@lemmy.ca ) 
            link
            fedilink
            English
            arrow-up
            2
            ·
            3 years ago

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

  • Miaou ( Miaou@jlai.lu ) 
    link
    fedilink
    arrow-up
    25
    ·
    3 years 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 ( OR3X@lemm.ee ) 
      link
      fedilink
      arrow-up
      9
      ·
      3 years ago

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

    • KillingTimeItself ( KillingTimeItself@lemmy.dbzer0.com ) Banned
      link
      fedilink
      English
      arrow-up
      3
      ·
      3 years ago

      i’m of the belief that pseudocode should be real code that actually runs. I.E. something like bash. A scripting language.

  • alexdeathway ( alexdeathway@programming.dev ) 
    link
    fedilink
    arrow-up
    23
    ·
    edit-2
    3 years ago

    Trick question?

    attribute error

    • Car ( Car@lemmy.dbzer0.com ) 
      link
      fedilink
      arrow-up
      14
      ·
      3 years ago

      Poor question more likely

      • alexdeathway ( alexdeathway@programming.dev ) 
        link
        fedilink
        arrow-up
        9
        ·
        3 years ago

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

        • Car ( Car@lemmy.dbzer0.com ) 
          link
          fedilink
          arrow-up
          8
          ·
          3 years ago

          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?”

          • alexdeathway ( alexdeathway@programming.dev ) 
            link
            fedilink
            arrow-up
            7
            ·
            3 years 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.

  • SquishyPandaDev ( SquishyPandaDev@yiffit.net ) 
    link
    fedilink
    arrow-up
    22
    ·
    edit-2
    3 years ago

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

  • jlow (he/him) ( jlow@beehaw.org ) 
    link
    fedilink
    arrow-up
    18
    ·
    3 years ago

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

    • blindsight ( blindsight@beehaw.org ) 
      link
      fedilink
      arrow-up
      4
      ·
      3 years ago

      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.

    • autokludge ( autokludge@programming.dev ) 
      link
      fedilink
      English
      arrow-up
      2
      ·
      3 years ago

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

  • ChaoticNeutralCzech ( ChaoticNeutralCzech@feddit.de ) 
    link
    fedilink
    arrow-up
    7
    ·
    3 years ago
    86400000
    
  • kubica ( kubica@kbin.social ) 
    link
    fedilink
    arrow-up
    4
    ·
    3 years ago

    The future is not yet young man.

  • mox ( mox@lemmy.sdf.org ) 
    link
    fedilink
    arrow-up
    3
    ·
    3 years ago

    hours = 0.25

    There. I fixed it! :)

  • Kühe sind toll ( cows_are_underrated@feddit.de ) 
    link
    fedilink
    arrow-up
    2
    ·
    3 years ago

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

    • PrettyFlyForAFatGuy ( PrettyFlyForAFatGuy@feddit.uk ) 
      link
      fedilink
      arrow-up
      1
      ·
      3 years ago

      deleted by creator

Programmer Humor@programming.dev

programmer_humor@programming.dev

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !programmer_humor@programming.dev

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

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics
    • If the mod doesn’t find it funny, you’re banned. Ha-ha!.. For real: do not use the community for “statements”. There are other places for such content. Keep it chill and funny.
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 622 users / day
  • 2.84K users / week
  • 5.18K users / month
  • 8.26K users / 6 months
  • 463 local subscribers
  • 33.9K subscribers
  • 1.62K Posts
  • 26.8K Comments
  • Modlog
  • mods:
  • Feyter ( Feyter@programming.dev ) 
  • adr1an ( anzo@programming.dev ) 
  • BurningTurtle ( BurningTurtle@programming.dev ) 
  • Pierre-Yves Lapersonne ( pylapp@programming.dev ) 
  • BE: 0.19.15
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code