Home › Forums › Decaffeinated Coffee › Computer Programmer
- This topic has 26 replies, 13 voices, and was last updated 13 years, 6 months ago by ZachKessin.
-
AuthorPosts
-
April 29, 2011 1:42 am at 1:42 am #596517ClairvoyantMember
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.”
April 29, 2011 4:45 am at 4:45 am #763811yossi z.MemberCute 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! 😀
April 29, 2011 6:26 am at 6:26 am #763812ZeesKiteParticipantAnd I thought you’re going to solve my calculusions.
April 29, 2011 6:42 am at 6:42 am #763813ZachKessinMemberCute, I like that (Yes I am a programmer)
April 29, 2011 9:59 am at 9:59 am #763814hanibParticipantyossi, 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? 😉
April 29, 2011 3:09 pm at 3:09 pm #763815Avram in MDParticipantClairvoyant,
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
April 29, 2011 3:28 pm at 3:28 pm #763816WolfishMusingsParticipantAvram,
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
April 29, 2011 3:30 pm at 3:30 pm #763817ClairvoyantMemberWhat 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)April 29, 2011 4:04 pm at 4:04 pm #763818Mayan_DvashParticipantClairvoyant’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.
;
April 29, 2011 6:19 pm at 6:19 pm #763819Avram in MDParticipantWolfishMusings,
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.
May 1, 2011 5:50 am at 5:50 am #763820yossi z.MemberBina: no I am not a mod just a poster who is having trouble finding the threads I post in to continue my conversations.
😀 Zuberman! 😀
May 1, 2011 10:05 am at 10:05 am #763821ZachKessinMemberIn Javascript:
var totalCartonsOfMilk = hasEggs()? 6 : 1;
lisp:
(let (totalCartonsOfMilk (if (hasEggs) 6 1)))
May 1, 2011 11:23 am at 11:23 am #763822hanibParticipantactually, 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.
May 1, 2011 2:02 pm at 2:02 pm #763823flowersParticipantMay 1, 2011 6:04 pm at 6:04 pm #763824HaLeiViParticipantThat 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?
May 1, 2011 6:35 pm at 6:35 pm #763825ZeesKiteParticipantSimpler:
GetWater.(thirsty? Glass : Null)
(bring mop)
May 1, 2011 9:59 pm at 9:59 pm #763826HaLeiViParticipantFor those monolinguals who don’t understand the java(/script) statement, in VB it would be IIF(Me.thirsty, water, Nothing)
May 2, 2011 12:14 am at 12:14 am #763827ItcheSrulikMemberA 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?
May 2, 2011 1:32 am at 1:32 am #763828ronrsrMemberwhy don’t programmers ever get out of the shower when washing their hair?
the instructions say, “Shampoo, rinse, repeat.”
May 2, 2011 2:34 am at 2:34 am #763829emlfMemberaargh! 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!
May 3, 2011 2:29 am at 2:29 am #763830ClairvoyantMemberIn 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
May 3, 2011 3:41 am at 3:41 am #763831ZachKessinMemberIs 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
May 3, 2011 4:41 am at 4:41 am #763832HaLeiViParticipantThanks. 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.
May 3, 2011 12:20 pm at 12:20 pm #763834ItcheSrulikMemberZach: 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.
May 3, 2011 2:17 pm at 2:17 pm #763835ZachKessinMemberIt 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)
May 4, 2011 1:27 am at 1:27 am #763836ItcheSrulikMemberI was thinking in terms of a locally hosted program in something like C++ or Java.
May 4, 2011 6:44 am at 6:44 am #763837ZachKessinMemberi don’t know about C++ or Java I don’t do ether language.
-
AuthorPosts
- You must be logged in to reply to this topic.