 |
 |
 |
 |
| | Fun article, hope it's OK, lol! |
|
 |
| This is just silly. You write an article about a bad piece of code you've written. If all you want is to compare two dates, representing them as integers are sufficient and less error-prone. The following is not something I would write for a real program, but is just for demonstration.
int conv(int year, int month, int date)
{
return (year * 100 + month) * 100 + date;
}
int compare(int y1, int m1, int d1, int y2, int m2, int d2)
{
return conv(y1, m1, d1) - conv(y2, m2, d2);
}
void test()
{
int res = compare(2009, 1, 31, 2009, 1, 21);
if (res > 0)
puts("Date #1 comes after date #2");
else if (res < 0)
puts("Date #1 comes before date #2");
else
puts("Date #1 and date #2 are equal");
}
|
|
 |
| ...and even simpler, you can represent dates as strings in the format "yyyy-mm-dd", which makes it possible to lexicographically determine the order.
void test()
{
string s1 = "2009-01-31";
string s2 = "2009-01-21";
if (s1 > s2)
puts("Date #1 comes after date #2");
else if (s1 < s2)
puts("Date #1 comes before date #2");
else
puts("Date #1 and date #2 are equal");
}
Conclusion: Don't blame the computer, blame the programmer. |
|
 |
| I disagree, cyph1e, I think this is a good article. Okay, his code is a little verbose - for the very purpose of the article. He's writing in code exactly how he described his mental process. Your code, however, is also how the article describes, you're just delegating to the string library to handle the comparison. You seemed to have missed the point - not every article on this site that includes code is there to say 'this is how you should code'.
The point I took away from it is that computers compute - they can do exactly what we ask of them, and they can do it repeatedly, very quickly - and sometimes, what we take for granted we have to reflect on how we do it in order to instruct a computer.
If you don't like it though, you're always encouraged to add an article you think others would enjoy! And log in to post, otherwise it looks like you're trolling. |
|
 |
| lol... I had a feeling something like this would happen.
I think Dom hit the nail on the head though. My target for this article is those that have little or no programming experience, to these people software "just does it" i wanted to show what happens in your head when asked the question "Which date is later" then coding it exactly as that.
It's a demonstration to those that assume computers/software have some level of intelligence, and shows you must hold their hand the entire way through.
Further more, this isn't a "bad piece of code i have written" as i said, it's a code representation of the logic any human would perform when comparing dates, and is meant to be just a bit of fun, no need to get critical. |
|
 |
| |
 |
| OK, on topic, I disagree that computers are stupid. I think they are as stupid as us. A month ago my girlfriend worked with litel children, orphans, ~10 years old. In my country the government doesn't spend a lot of money for their proper rise. So she told me thay can't differentiate the colors. Why they can't ? Simply becouse no one taught them what is black and what is white. Maybe it sounds strange to you but it is true. Someone has to teach them like you have to "teach" the computer how to execute a task.
P.S. Didn't want to mention but some of them at that age can't even read. |
|
 |
| You don't "teach" a computer anything, this is my point, it doesn't learn, if in one application it hashes HELLO WORLD, and you execute another application which does the same thing, it doesn't "remember" the hash, it has to do it all again. Some people attribute some form of intelligence to the machines we use, that they are intuitive, but they cannot learn, they are not intuitive and they are not clever. The code is. Computers are not only stupid, they have ZERO intelligence.
I think this is all getting a bit to much, my aim was to show the thought process for something humans consider easy we do things like this without really thinking about it, then demonstrate the steps you have to go through to duplicate that thought process in code.
This article came to fruition because of some code i was writing a while ago, someone asked me "Why doesn't the computer just know the pixel is black?" - That says a lot to me in terms of peoples expectations. It also adds credence to why most managers of software developers (who aren't developers themselves) have unrealistic expectations of their staff, they simply expect too much from the machines we use. |
|
 |
| Well, Domuk. In defense, my first code didn't rely on any library function and the second is just using char-by-char comparison, which is trivial. It was meant to point out the importance of how you represent data. Moreover, a programmer might need to think further about a problem than implementing straight-forward case-by-case work. In this case, making 3*n comparisons, where n is the number of fields in the date, and ending up with the conclusion "Computers.... total morons!" is to me not a good article.
Sure, if the article pointed out that doing what immediately comes to mind might end up being troublesome, it could have saved it. I don't see why you consider these types of posts as trolling. I might sound a bit negative though, I admit that. Why do you have the option to anonymous comment if you take (critical) anonymous posts as trolling?
I also understand that this wasn't meant to be anything more than it is, but I also think that some articles on this site doesn't really qualify. |
|
 |
| I took it as trolling as at some point, you were a user who was active enough to register in my memory, who six months later comes back and anonymously criticises some code that clearly wasn't written as the best code to solve a problem. It wasn't the point of the article.
My point about the string library was that character-by-character comparison is essentially the algorithm proposed above - "check the year - is it higher? no, it's the same - check the month" - just on a more precise level. Exactly as we do - if we want to know which year is less, and we are given the dates 24/3/2009 and 21/4/1666 we (theoretically) see the '1' and immediately stop processing.
Your first example is basically the same, just multiplying numbers to a point where the years/months/days are distinct, to avoid using strings.
The fact that the code uses a lot of 'if' statements isn't why he comes to the conclusion 'computers are stupid'. Anyone who codes surely knows that - 'computers are stupid' is an idea that's been used a lot, talked about a lot, and I'd be really surprised if anyone who codes hadn't come across it. |
|
 |
| The whole article is built upon the example of comparing two dates by using the straight-forward logic we all use daily. He then implements it right off and spells it out in words to make it sound complicated. At least when I read it I found it focusing on how complicated it turned out when typing the code, not to show that the computer is essentially a calculator.
Obviously my code does essentially the same. One must compare dates in a certain way. I didn't think that needed clarification. |
|
 |
| | "Anyone who codes surely knows that - 'computers are stupid' is an idea that's been used a lot, talked about a lot, and I'd be really surprised if anyone who codes hadn't come across it." - I'm surprised at the reaction here... are people claiming computers are not stupid, that they are in fact intelligent? Maybe "computer's are stupid" is the wrong terminology, maybe "Computers have no intelligence what so ever and please stop thinking that they know what you want them to do" is a better title? |
|
 |
| | cyph1e, i don't "make it sound complicated" that is exactly what goes on in your head when you determine date matches, I'm all for negative criticism, but this is intended as a fun article, you're actually beginning to get insulting on the matter. |
|
 |
| | Sorry MaxMouse, I didn't mean to offend you. I'm just used to write in a certain way. |
|
 |
| | This isn't intended to be "the right way" that's why my first comment is that its a "fun article" it did make you think about how you determine date differences, you even wrote some example code. So i guess even in a negative way, my article did hit home. |
|
 |
| | You aren't my target audience though lol... |
|
 |
| Hey MaxMouse disregard some comments above...
The purpose of your article should be quite obvious for everyone.
If someone does not like it, that is his choice but no one should not leave irrelevant and immaterial comments.
If you see a bug it the code or you think you can improve author’s approach to the problem or perhaps you can see other, alternative, way to grasp it, that’s different matter – this is constructive and more than welcome.
If you think you are smarter, prove it by writing you own article and have some respect for the people spending their own time trying put something to the community. |
|
 |
| | lol, controversial subject, the comments are larger than the article! |
|
 |
| * The day of date 2 is higher than date 1
* Compare month and year, the same
* Therefore date 2 is later than date 1
I dunno how you guys think, but I believe that was how I get it, because I read from left to the right, not right to the left. More human-like, no?
Saying smart or stupid is depend on how you define the word of "stupid" and "smart". When you define smart as able to do lots of mathematics given a very little time, of course computer is very smart.
Anyway, let's see what internet says:
Define: stupid
"lacking or marked by lack of intellectual acuity "
Define: intellect
"The faculty of knowing and reasoning"
Conclusion: Computer may know but may not reason -> Computer doesn't fulfill intellectual definition -> Computer is stupid
Nothing is absolute,
Vk21 |
|
 |
| | A computer is only as intelligent as the instructions it is given. |
|
 |
| "A computer is only as intelligent as the instructions it is given." - My point exactly!
* The day of date 2 is higher than date 1
* Compare month and year, the same
* Therefore date 2 is later than date 1
That works for only one instance, you must cater for ALL instances, and ALL dates, if you read left to right, or right to left the logic is the same.
Try reading the article again. |
|
 |
| When you define smart as able to do lots of mathematics given a very little time, of course computer is very smart - If you define smart as being able to fit a lot of marshmallows in your mouth at the same time, of course i am very smart...
The ability to calculate 1+1 or 9^10^100*4 is NOT smart. |
|
 |
| Also... computers get math wrong... a lot...
http://www.codinghorror.com/blog/archives/001266.html
http://www.math.niu.edu/~rusin/known-math/99/calc_errors |
|
 |
| |
 |
| | Anonymous, it is for people who are not only ignorant of computer science, but mostly ignorant of how a computer's logic works. As for my conver.... flame-war.. with abs(0), yes, little stupid, I've been involved in a couple of flames there in recent months, i should stop it. |
|
 |
| | Also, if you find this article "retarded" why don't you write a better one? |
|
 |
| That's brave, Anonymous - not only baselessly criticising an article but actually cyberstalking the author to criticise their contributions to other communities.
Go boil your head. |
|
 |
| | so one computer, with no code, assembly or lesser. if i just start typing at a keyboard is goin to figure out mathmatical equasions still. cause i don't see that happening, n though anon is apparently the absolute in programming today.. cannont wrap your head around this article still? |
|
 |
| | I agree with Max, computers are stupid, i mean geeks... they just can't do anything without an intsruction. And if they were smart they wouldn't provide a wrong output if someone have input wrong information.... they are stupid |
|
 |
| | Can't wait for next article: "Hard disks can't swim" |
|
 |
| | lol.... wtf?! hard disks can't swim? |
|
 |
| | I suspect that was sfabriz's point, as its as its pretty much as true that computers are stupid |
|
 |
| | what your talking about is the INTERNET not computers ! DAA! all your talking about is the interney! gosh doof! |
|
 |
| I honestly don't think that we should talk about the intelligence of computers since they're just some kind of machine (a bit more complex than mechanical machines, since computers are programmable).
"A computer is only as intelligent as the instructions it is given. " - I agree with this line :), but "intelligent" should be swapped with "competent" or "capable" since intelligence is something much more abstract than the sum of your abilities to operate some data. Cheers |
|
 |
| they are neither intelligent nor dumb, they are just tools to achieve some purpose.
if computer becomes intelligent then HAL 9000 thing will happen |
|
 |
| | Computers are stupid by itself. As an assembly programmer, I can tell you that the smartest thing a computer can do is cmp something, something else and set flags. A computer is as smart as its programmer. |
|
 |
| |
 |
 |
 |
 |
Anonymously add a comment: (or register