Computer Programmer

Home Forums Decaffeinated Coffee Computer Programmer

Viewing 27 posts - 1 through 27 (of 27 total)
  • Author
    Posts
  • #596517

    Clairvoyant
    Member

    A wife asks her husband, a computer programmer; “Could you please go to the store for me and buy one carton of milk, and if they have eggs, get 6!”

    A short time later the husband comes back with 6 cartons of milk.

    The wife asks him, “Why did you buy 6 cartons of milk?”

    He replied, “They had eggs.”

    #763811

    yossi z.
    Member

    Cute joke but please put things where they belong next time like the joke thread. I am not trying to sound harsh or anything just that people aren’t watching what kind of a mess this place is turning into

    😀 Zuberman! 😀

    #763812

    ZeesKite
    Participant

    And I thought you’re going to solve my calculusions.

    #763813

    ZachKessin
    Member

    Cute, I like that (Yes I am a programmer)

    #763814

    hanib
    Participant

    yossi, what’s wrong – it’s getting to disorganized?

    are you one of the new mods who was left having to clean the CR room for pesach? 😉

    #763815

    Avram in MD
    Participant

    Clairvoyant,

    When I ran her request, I returned 7 cartons of milk:-)

    The pseudocode for her request:

    totalCartonsMilk = 1 # She asked to get 1 carton of milk separate from the if-statement.

    if(eggs) {

    totalCartonsMilk = totalCartonsMilk + 6

    }

    return totalCartonsMilk

    #763816

    WolfishMusings
    Participant

    Avram,

    I don’t think your approach is correct. She didn’t ask for six MORE cartons, she asked for six (in total).

    totalCartonsofMilk = 1

    If(eggs) {

    totalCartonsofMilk = 6

    }

    return totalCartonsofMilk

    The Wolf

    #763817

    Clairvoyant
    Member

    What the wife actually said:

    .
    #!/usr/bin/env python

    from SuperMarkets import check_out, find_markets, inventory

    def run_errand(milk, eggs):
    shopping_cart = []
    if 'milk' in inventory and 'eggs' in inventory:
    shopping_cart.append(milk * 6)
    elif 'milk' in inventory and 'eggs' not in inventory:
    shopping_cart.append(milk)
    else:
    print 'Store has no milk. Try another.'
    find_markets()

    check_out(shopping_cart)

    if __name__ == '__main__':
    run_errand(milk='milk', eggs='eggs')

    .

    What the wife should have said to her programmer husband:

    .
    #!/usr/bin/env python

    from SuperMarkets import check_out, find_markets, inventory

    def run_errand(milk, eggs):
    shopping_cart = []
    if 'milk' in inventory and 'eggs' in inventory:
    shopping_cart.append(milk + eggs)
    elif 'milk' in inventory and 'eggs' not in inventory:
    shopping_cart.append(milk)
    elif 'eggs' in inventory and 'milk' not in inventory:
    shopping_cart.append(eggs)
    print 'Buy eggs, then go to another store for milk.'
    find_markets()
    else:
    print 'Store has no eggs or milk. Try another.'
    find_markets()

    check_out(shopping_cart)

    if __name__ == '__main__':
    run_errand(milk='milk', eggs='eggs' * 6)

    #763818

    Mayan_Dvash
    Participant

    Clairvoyant’s point is right-on! As per requirements, there were no errors or bugs. Additionally, suppose one were to assume that the husband knew to buy eggs if they had, does he buy 6 eggs or 6 dozen? The proper response in this case, is for the husband to send back the spec for clarification and official sign-off.

    ;

    #763819

    Avram in MD
    Participant

    WolfishMusings,

    Oy, so that’s why my wife said I didn’t understand her. Next time I’ll bring home 6 and all will be well:-)

    In reality, if we wrote the code literally per her request, the “get 6” would not act on a variable, so some interpretation is needed.

    #763820

    yossi z.
    Member

    Bina: no I am not a mod just a poster who is having trouble finding the threads I post in to continue my conversations.

    😀 Zuberman! 😀

    #763821

    ZachKessin
    Member

    In Javascript:

    var totalCartonsOfMilk = hasEggs()? 6 : 1;

    lisp:

    (let (totalCartonsOfMilk (if (hasEggs) 6 1)))

    #763822

    hanib
    Participant

    actually, yossi, i understand – i have the same problem. ’tis does get a little mind-boggling; though, i’m as guilty as all the rest, at least once i’m in a thread.

    #763823

    flowers
    Participant
    #763824

    HaLeiVi
    Participant

    That is only for the one line

    getGlassOf(this.thirsty? water : null)

    However, if you’d write out the

    if (this.thirsty)

    getGlassOf(water)

    you wouldn’t need the empty one. On the other hand, thinking like a programmer you’d say it’s simpler to just bring two.

    Is there an actual difference in process time between the two methods, Zach?

    #763825

    ZeesKite
    Participant

    Simpler:

    GetWater.(thirsty? Glass : Null)

    (bring mop)

    #763826

    HaLeiVi
    Participant

    For those monolinguals who don’t understand the java(/script) statement, in VB it would be IIF(Me.thirsty, water, Nothing)

    #763827

    ItcheSrulik
    Member

    A programmer wouldn’t leave two glasses. He would write pseudocode for a PDP-8 assembler subroutine:

    098 load full

    099 store glass

    100 load thirsty //there aren’t any types in PDP-8 so we improvise.

    101 skip cond 800 //if thirsty is greater than 0 i.e. true

    102 clear glass //drink

    103 jump 098

    I’m taking a class where we have to code in PDP-8 assembler for some reason even though nobody including the professor has ever used one, so I had to get some fun out of it ;). Anyone spot the logical error?

    #763828

    ronrsr
    Member

    why don’t programmers ever get out of the shower when washing their hair?

    the instructions say, “Shampoo, rinse, repeat.”

    #763829

    emlf
    Member

    aargh! I took – or should I say, suffered through – two courses in Java last year so I have a slight inkling of what’s going on here – and I also know that for me, computer programming is not at all shayach!

    Cute, I must admit!

    #763830

    Clairvoyant
    Member

    In the beginning God created the Bit and the Byte. And from those he created the Word.

    And there were two Bytes in the Word; and nothing else existed. And God separated the One from the Zero; and he saw it was good.

    And God said – Let the Data be; And so it happened. And God said – Let the Data go to their proper places. And he created floppy disks and hard disks and compact disks.

    And God said – Let the computers be, so there would be a place to put floppy disks and hard disks and compact disks. Thus God created computers and called them hardware.

    And there was no Software yet. But God created programs; small and big… And told them – Go and multiply yourselves and fill all the Memory.

    And God said – I will create the Programmer; And the Programmer will make new programs and govern over the computers and programs and Data.

    And God created the Programmer; and put him at Data Center; And God showed the Programmer the Catalog tree and said You can use all the volumes and subvolumes but DO NOT USE Windows.

    And God said – It is not Good for the programmer to be alone. He took a bone from the Programmer’s body and created a creature that would look up at the Programmer; and admire the Programmer; and love the things the Programmer does; And God called the creature: the User.

    And the Programmer and the User were left under the naked DOS and it was Good.

    But Bill was smarter than all the other creatures of God. And Bill said to the User – Did God really tell you not to run any programs?

    And the User answered – God told us that we can use every program and every piece of Data but told us not to run Windows or we will die.

    And Bill said to the User – How can you talk about something you did not even try. The moment you run Windows you will become equal to God. You will be able to create anything you like by a simple click of your mouse.

    And the User saw that the fruits of the Windows were nicer and easier to use. And the User saw that any knowledge was useless – since Windows could replace it.

    So the User installed the Windows on his computer; and said to the Programmer that it was good.

    And the Programmer immediately started to look for new drivers. And God asked him – What are you looking for? And the Programmer answered – I am looking for new drivers because I can not find them in the DOS. And God said – Who told you need drivers? Did you run Windows? And the Programmer said – It was Bill who told us to !

    And God said to Bill – Because of what you did you will be hated by all the creatures. And the User will always be unhappy with you. And you will always sell Windows.

    And God said to the User – Because of what you did, the Windows will disappoint you and eat up all your Resources; and you will have to use lousy programs; and you will always rely on the Programmers help.

    And God said to the Programmer – Because you listened to the User you will never be happy. All your programs will have errors and you will have to fix them and fix them to the end of time.

    And God threw them out of the Data Center and locked the door and secured it with a password.

    GENERAL PROTECTION FAULT

    #763831

    ZachKessin
    Member

    Is there an actual difference in process time between the two methods, Zach?

    I suspect not much if any, it would depend a LOT On the compiler and language we are talking about. In Haskell you must have the else clause for reasons that are not worth going into here, in other cases it just depends on programmer style and things like that

    #763832

    HaLeiVi
    Participant

    Thanks. I think I’ve noticed a difference in javascript between running a calculation over and over (that computers just love doing) and creating a ready made object. It seems that object instances are a heavier load than running calculations.

    #763834

    ItcheSrulik
    Member

    Zach: Wouldn’t HaLeivi’s second method be faster? In the second method, he only calls the function if this.thirsty returns true. In the first one, he calls it every time which means it will often return null.

    #763835

    ZachKessin
    Member

    It really depends on what you are trying to do, creating an object in Javascript is pretty fast. Running a long calculation in Javascript will cause the browser to block as there is only one thread of execution. Though with modern browsers you can use web workers. But the two tend to be used for very different things.

    I have to say Javascript is one of my favorite languages, and I spend about 80% of my work day working in it. (Though I will admit haskell and erlang are growing on me)

    #763836

    ItcheSrulik
    Member

    I was thinking in terms of a locally hosted program in something like C++ or Java.

    #763837

    ZachKessin
    Member

    i don’t know about C++ or Java I don’t do ether language.

Viewing 27 posts - 1 through 27 (of 27 total)
  • You must be logged in to reply to this topic.


Trending