Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

IT Professionals

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

Search

XML Feeds

Google Ads

« Windows 7 Launch In New York CityFive Google Wave Invitations are up for grabs »
comments
Rate Post:
submit to reddit Digg!FacebookDotnetkicks

This is kind of a semi rant so if you don't like to read those kind of things feel free to skip this post.

How much math does a programmer need to know to do his job? These days with all the frameworks that exists you don't need to know how to do a square root, a power function or a quick sort these will likely already be built in. What perplexes me is that someone would come out with a function to flip a sign. So if the number is 5 make it -5 and if it is -5 make it 5. Isn't this simple math? Multiply by -1 and you are done!!

Take a look at this function that someone created on StackOverflow

Math opposite sign function?
Does such function exist? I created my own but would like to use an official one:

  1. private function opposite(number:Number):Number
  2.         {
  3.                 if (number < 0)
  4.                 {
  5.                         number = Math.abs(number);
  6.                 }
  7.                 else
  8.                 {
  9.                         number = -(number);
  10.                 }
  11.                 return number;
  12.         }

If we visit the Java forums it doesn't get any better, take a look at this thread: How do you Invert signed numbers?

Hi there.

A simple question: How can I invert the sign of an integer? ie) convert -12 to +12? No doubt there is a really simple way to do this, but I'm stumped, I cannot find anything and I've been working on this program all day.

I'll be very grateful to anyone who can let me know if Java provides a way to do this, or point me in the right direction if it takes some tweaking of binary numbers using the Math package or something.

Cheers!

Here is one 'solution'

  1. int x = numberToInvertSign;
  2. boolean pos = x > 0;
  3. for(int i = 0; i < 2*Math.abs(x); i++){
  4.    if(pos){
  5.       numberToInvertSign--;
  6.    }
  7.    else{
  8.       numberToInvertSign++;
  9.    }
  10. }

You have to love this 'gem' (of course this is someone messing with the original poster)

  1. switch (i)
  2. {
  3.   case 1: return -1;
  4.   case 2: return -2;
  5.   case 3: return -3;
  6.   // ... etc, you get the proper pattern
  7. }

Looking at the php documentation for the ABS function we find a bunch of comments and replies to create a sign function




Isn't this just basic math that was taught to us in grammar school? Of course it doesn't stop here, how many people these day can convert numbers between hexadecimal (base-16), binary (base-2) and decimal (base-10) without using a tool?
Of course the future is that people will rely more and more on frameworks and wizards, this could be bad if you need to fix something in your code. Take a look at jQuery, people just love this because JavaScript is hard and they don't have to deal with it...the tool shields them from that. Another example is ORM....people hate writing queries and just want to create some classes and then some tool will spit out all the CRUD code for them. Sometimes these tools produce some bad SQL and it takes a effort to figure out why your calls to the DB are suddenly slow

Enough ranting for the day....
What do you think is it inexcusable that a programmer does not know that you can flip a sign by doing the following

return -number

or

return number * -1

About the Author

User bio imageDenis has been working with SQL Server since version 6.5. Although he worked as an ASP/JSP/ColdFusion developer before the dot com bust, he has been working exclusively as a database developer/architect since 2002. In addition to English, Denis is also fluent in Croatian and Dutch, but he can curse in many other languages and dialects (just ask the SQL optimizer) He lives in Princeton, NJ with his wife and three kids.
Social SitingsTwitterFacebookLinkedInHomePageLTD RSS Feed
9891 views
math, rant
submit to reddit Digg!FacebookDotnetkicks

Comments and Feedback

44 comments

Comment from: Steve Jones [Visitor] · http://www.sqlservercentral.com
****-
I think this is a problem. We are not emphasizing fundamentals enough in education. It's one reason that I think that every programmer/CS person should still start with Pascal or C and dig through how things work. Learn to sort things, work with pointers, etc.
10/05/09 @ 08:21
Comment from: traingamer [Member] Email
*****
A basic understanding of math is a must. You don't have to be know how to calculate Pearson's Correlation Coefficient (unless you're actually doing statistical work), but a knowledge of simple math is essential. I always thought those questions on various forums were fake, but after meeting some people who pass for programmers, I'm not so sure.
10/05/09 @ 08:24
Comment from: Ted Krueger (onpnt) [Member] Email
*****
I'm with Steve. I started out programming on the 400 in cobol and RPG (control language and all that fun). I ahted it but you know, it gave me what I needed to do my job really well to this day.

Great post Denis!
10/05/09 @ 08:27
Comment from: Raghuram (AJ) [Visitor] · http://ajscript.wordpress.com
****-
Nice article! I agree programmers need to have 'common math sense'. Like Steve Jones pointed out, it helps if the first programming language is Pascal or C.
10/05/09 @ 08:46
Comment from: George Mastros [Member] Email
*****
I think this goes beyond "basic math". If a programmer cannot (on his own) figure out how to reverse the sign of a number, what else can this programmer "not do". That's not to say that this programmer cannot learn enough to effectively do his job, but what an uphill climb!

Some people tend to be more suited for a programming position than others. Most programming tasks (if broken down in to bite size pieces) usually have a simple and elegant solution for them. An experienced programmer will recognize that solution... an inexperienced programmer will hack their way to a slow-loopy solution.
10/05/09 @ 08:52
Comment from: SQLRockstar [Visitor] · http://thomaslarock.com
quick question for everyone that has jumped on the "people should be smarter" bandwagons...

do you know how old-schol calulators work?

what may seem simple to someone that has pencil and paper at hand, put yourself in the shoes of
someone that has to program a calculator and be able to calculate just about anything.

not everyone thinks the same way. we should be thankful that others see things differently,
that is what allows for advancements to take place.
10/05/09 @ 09:19
Comment from: Adam Machanic [Visitor] · http://sqlblog.com
Mathematics is universal, and is the basis for how computers work. If you don't know basic math, you have no business programming. I'll be (once again) very unpopular for saying this, but the solution from a hiring perspective is easy: only hire people with a degree in CS, math, or an engineering discipline.

Yes, some people think differently. And those people had better not get anywhere near my data. They can work in marketing, HR, or any number of other positions that don't require the kind of thought processes that good programmers need.
10/05/09 @ 10:12
Comment from: Jen McCown [Visitor] Email · http://www.MidnightDBA.com
****-
Great post! I guess I'm not all that surprised to know that we have a few, uh, sub-sub-average coders out there. As much as I'd like to say, "hey, everybody skips a groove now and then", I expect that some of these people actually don't get that whole *-1 thing...
10/05/09 @ 10:17
Comment from: sqlsister [Member] Email
*****
If you don't understand basic algebra, you have no business coding. Maybe you don't need advanced math, but it certainly helps. If you can't figure out that to change the sign on a number you have to mulitply by -1, then you need to get into a new profession as the other problems you will encounter in programming are much harder than this one. If you can't solve the simple stuff, there is no hope at all that you will be any good at doing the complex tasks.

If you don't thoroughly understand Boolean algebra then you have no business querying a database as you have no basis to judge if your query gives the correct answer to the question.
10/05/09 @ 11:16
Comment from: Emtucifor [Member] Email
*****
SQLRockstar: "Thinking differently" in a way that creates advancements is wonderful. But when "thinking differently" is just a euphemism for "mathtard", then that person shouldn't be programming. Sorry.

Adam Machanic: I don't have any degrees at all, let alone in CS, math, or engineering. And I think I'm very skilled in my profession (and I love math and excel at it). I realize that a degree can be a good, easy filter, but it's not perfect. You would miss out if you excluded me as a candidate just because of an arbitrary rule like that.

In fact, I bet that people can manage to get a degree in one of those disciplines and be a LOT worse at math than I am...
10/05/09 @ 11:26
Comment from: riverguy [Member] Email
*****
Anyone with a job should know "basic math" period. There's nothing special about being a programmer which should require math over any other job. The term "programmer" is too wide to make any sweeping generalizations. I might go out on a limb, however, and suggest that a programmer should have a basic understand of computers ;).

Anyways, if you wish to write scientific simulation software, you should probably be VERY good at different types of math. If you wish to write applications to manipulate data in databases, then I think you would be well prepared with a basic competency of math/algebra/basic geometry.
10/05/09 @ 12:27
Comment from: Cade Roux [Visitor] Email · http://www.semicolon.net
*****
Wow, I've seen some bad stuff, but probably never this bad. Not knowing -1 * x changes the sign of x is pretty unforgivable. It's not like you have to do any bit operations or knowing if your representation of negative numbers uses two's complement.

And it's pretty universally practical in terms of usage in a LOT of different areas of computing - how often do you need to negate something in accounting software in SQL or ecommerce shopping carts in PHP or reporting formulas or GUI layout?

Someone who doesn't know this would not get through the first page of Knuth...
10/05/09 @ 13:27
Comment from: tarwn [Member] Email
Firstly, Denis, I enjoyed the post very much, Thanks :).

I do, however, find myself disagreeing with Adam that tossing every resume without an engineering, CS, or math degree is a good way to protect ourselves from these types of situations. You will lose a lot of good developers with this method and I have worked on enough legacy code-bases and data systems to know that a degree does not guarantee logical design, implementation, or maintainability. Having read a number of your posts in the past I know you have a tendency to throw around inflammatory comments, but I'm not sure if your trying to honestly spark a debate, provide us with an estimation of your character, or simply relieve a little midday tedium.

While I know this conversation and topic has been discussed to death all over, I invite everyone to join us in the forums to discuss it further. We all have unique (and mostly valid) opinions and experiences, might as well share :)
10/05/09 @ 13:57
Comment from: Claude [Visitor] · http://claude.betancourt.us/
****-
@Adam Machanic: You'd be amazed at the number of people I've come across *professionally* with CS degrees (and MS and MBAs) who can't employ simple logic to solve the most basic problems. I don't know how those people even got into college to start.

Math and water are the real basis of life. :)
10/05/09 @ 14:47
Comment from: I'm the one who asked the question [Visitor]
Hi, I'm the one who asked the question.

I was having a bit of a brain failure. That's the best excuse I can come up with. I do believe I've a good understanding of math though -
for whatever it's worth, I took differential equations last semester and received an A (from a decent university).

Sorry to have made you weep for humanity, or programmers. :)
10/05/09 @ 16:02
Comment from: Ted Krueger (onpnt) [Member] Email
*****
posting that comment with the level of restraint shown was impressive. Good form and good luck in the future.
10/05/09 @ 22:30
Comment from: SQLDenis [Member] Email
[sarcasm]maybe we should have a BrainBench simple math certification...after all they have a HTML 4.0 one they could add the math one [/sarcasm]
10/06/09 @ 06:33
Comment from: Alex Ullrich [Member] Email
Thanks for commenting, "The one who asked the question" - everyone has a "brain failure" from time to time and often these questions end up on the internets for everyone to see.

While I do think that people in general should know basic math, its' probably unfair to assume someone doesn't have this understanding based on one forum post (if that was all it took, I probably would have been banned from ever touching a computer again years ago).

That being said, we all see "repeat offenders" that clearly don't get it - I don't mean to put words in Denis' mouth but I think that these folks were the target of the rant.

I'm glad that you seem not to have taken it personally (you just happened to be a convenient example :) )
10/06/09 @ 06:55
Comment from: thirster42 [Member] Email
*****
I agree. Although i'm a noob to the programming world, so what do i know?

Btw, i can convert between decimal, binary, and hexidecimal :-D
10/06/09 @ 07:17
Comment from: thatrickguy [Member] Email
****-
To be fair, a good number of those "answers" were designed to perform the desired function in the most ridiculous way possible. I know, because I wrote a similar answer long ago that was a multi-threaded solution using pointers and a database to find the opposite value of X.

Such threads become a source of one-up-man-ship where each developer attempts to cram more unnecessary functionality, bloat, and insanity into a solution that could be written in about 10 characters.

That said, ALWAYS google before posting. That way, only Google will know when you have brain farts ;)

-Rick
10/06/09 @ 09:07
Comment from: genomon [Member] Email
*****
Nice catch, Denis!
Let's not forget about set theory and its place in RDBMS & schema design, SQL joins, etc. Granted anyone can throw together a table in design view, but without this knowledge & basic understanding of Boolean logic & math I think you are at a serious disadvantage. Especially if you plan on becoming a DBA or Software Engineer, not to mention a programmer. This was taught in High School (and, of course, college) when I attended. That was quite some time ago. Have the educational requirements for graduation changed that much in 30 years?
10/06/09 @ 11:48
Comment from: SamBhau [Visitor]
*----
Maths == Logical/Reasoning Skills.

Rest is bullshit!!!
10/06/09 @ 14:09
Comment from: Jason [Visitor]
*****
I like the first Java implementation haha. It took me a few min to understand it. Just for fun, I have a variation of it, without the loop, but with the same intention as the original

//
numberToInvertSign = numberToInvertSign - 2 * numberToInvertSign
//

Same dumb implementation but cleaner!

10/06/09 @ 14:24
Comment from: O God! [Visitor] Email · http://www.jobspath.com
*----
Computers/Coding without complex math alghoritms is nothing, is look like hanky-panky.
Computers are linked with math.
10/06/09 @ 15:55
Comment from: JG [Visitor] Email
*****
Actually most schools in the US *do* emphasis fundamentals and "basic math" in a 3R sense but it's not simply fundamentals that are required. Rote fundamentals exactly what standardized tests are optimized for and in fact it's the only thing that standardizes tests can detect. When you only tool is a hammer, every problem looks like a nail and you only product (student who are) nail hammerers! Most competent teacher know this well but they usually micromanaged by unions, politicians, bureaucrats and too often parents who are complete morons.

You have to have interest and context to make any fundamental skill stick and every be usable. A real case of "you can lead a horse to water but not make him drink". Learning the "3 R's" does no good without having interest and context because these are essential to building the foundation of "critical thinking".

The problem is that it's not possible to simply use a cookbook recipe teaching or learning style to get "critical thinking". You also can't really test for it short of throwing somebody into a problem that forces them to use and develop practical skills.

This is what "apprenticeship" used to and are supposed to "systematize" despite not really being systematizable in a normal bureaucratic/technocratic wet-dream sense.
10/06/09 @ 18:41
Comment from: Cay Horstmann [Visitor] · http://horstmann.com
*****
I teach computer science in a state university and happened to give an exam today, asking students to give a javadoc comment for this method:

public Rectangle makeRectangle(int x, int y, int width, int height)
{
int newX = x - width / 2;
int newY = y - height / 2;
Rectangle rect = new Rectangle(newX, newY, width, height); // plain old java.awt.Rectangle
return rect;
}

ONE student out of 30 figured out that the rectangle's CENTER is (x,y). Everyone else either claimed that (x,y) is the top left corner, or just said something wishy-washy about it being the "starting position" or some such thing. A heap of shame on the secondary education system that produces a herd of innumerates!
10/06/09 @ 21:16
Comment from: Certpal [Visitor] · http://www.certpal.com/blogs/
****-
I love the switch case thing. Wonder if the OP actually implemented it :D
10/06/09 @ 21:42
Comment from: Naomi [Member] Email
BTW, I completely forgot about recent question in ASP.NET forums

http://forums.asp.net/t/1476612.aspx

10/06/09 @ 22:07
Comment from: Gilberto [Visitor]
Programmers must understand logic. I started programming z80 assembly games when I was 13, and I really hated math at that time. Nowadays some kids are able to program when they are 8 or 9 years old.

I agree that most jobs require at least a basic math (sophisticated games requires a lot of math), but I strongly disagree that math is essential to become a good programmer.

Although many people think that math is the only way to teach logic, I believe that it's not the natural way for learning it. And it's interesting to see that some 20+ years old people can't understand it and a 9 years old child can.
10/07/09 @ 07:23
Comment from: Justin Etheredge [Visitor] · http://www.codethinked.com
*****
Ha ha ha, this post made my day. Thank you.
10/07/09 @ 08:28
Comment from: Andrey [Visitor] Email · http://blogovski.net
*****
I never tought that such programmers could exist. I found this post very funny. In my country no abiturient will have a chance to go study programming in university if he won't pass a state math exam. And at the universtity we had 10 diffrent math courses. But we had a very small amount of programming cources that is a my regions problem. We have a very few skilled developers and a very few of them are willing to teach.

In my opinion math is one of the main requirements in game, 3d or heavy software for buisness development. But if a programmer is willing to develop cheap websites, then he does not need knowledge of math.

I can't agree with your opinion about ORM. ORM is a great way to save time. When writing buisness logic I found that it takes 3x more time to create it and 3x more logic bugs are more likely will be created using basic queries. But one should generate a perfect sql skill and then use Object Relational Mapping to make a perfect use of it.
10/07/09 @ 08:50
Comment from: Mark [Visitor]
*****
Everyone should understand basic math! @Steve Jones suggests students learning C or Pascal, I will take it farther, teach the students Assembly! There both Math and Logic is required. When I was in college, Assembly was dropped from the degree(It was too hard for students and "no one" writes assembly anymore). I convinced the instructors to let me take the course as an advanced self study course. I felt that if I could not write Assembler code, I had no business with a CS degree.
Now having said all that, Math and Logic are two different creatures. I would rather maintain code written by a poet, philosopher or a engineer than a Mathematician. As quick as I see throw-away functions or Lambda's, I start refactoring.
10/07/09 @ 09:06
Comment from: Henry [Visitor]
*****
It doesn't seem to me that it's merely a math problem. Certainly not in the case of the StackOverflow poster. He seems to have known the math of how to reverse a sign. What's interesting is, he didn't seem to connect that piece of knowledge with his problem. That's not uncommon. It's kind of a "not seeing the trees for the forest" thing. People get lost in the complexity of what they're doing and fail to perceive simple, known, solutions to their problems. A programming problem must require a programming solution. Well, maybe not. In this case, it simply required a math solution. It's an interesting phenomenon, and not uncommon in history, though I can't remember an example right now.
10/07/09 @ 11:11
Comment from: Rob Whelan [Visitor] Email · http://blog.robwhelan.com
***--
The *-1 example is a good one, and I certainly understand the rant. But the other examples? ORM has nothing to do with math, nor does using a JavaScript library like jQuery.

JavaScript is "hard" because it's a huge headache to deal with all of the browser incompatibilities and bugs. Whenever I used to flip from solving problems in Java to (vanilla) JavaScript it was like a slap in the face -- I'd write correct code, and it would fail for obscure and stupid reasons that had nothing to do with my problem-solving ability. Now I'm very glad to paper over those huge flaws with mootools, jquery, etc..

ORM is related -- bridging over the generally pointless differences between many implementations of SQL and generally removing the need for a lot of boilerplate code -- though I admit that for any non-trivial application, I use tools that take standard SQL (which I can optimize, tweak, etc.) and load the results into objects.

But back on topic -- the real problem is rote-learning. Students are "taught" low and even high-level math by memorizing formulas and techniques, with NO clue as to what they're actually doing. They learn that a problem in form X gets solved with technique Y but the numbers themselves are still meaningless to them. If they make a calculation error and get a result an order of magnitude off... they won't notice. They also will be totally unable to identify a real-world problem they would solve using their math.

And because they never get an actual acquaintance with numbers in the real world, their mental muscle for problem solving is incredibly weak, and they make horrible programmers. (Likewise with those taught programming via rote-learning...). Faced with an actual problem, they just throw their memorized techniques at it randomly until one seems to work.

Interestingly (particularly for anyone saying you should only hire those with CS or math degrees), I was already majoring in music more than a decade ago when I started writing code to solve actual problems, and it was continually surprising to me that when I did take compsci classes, there were plenty of students with far more CS background than me... who still had no clue how to logically work through a problem. They were pretty useless at debugging. They graduated, though.

I'm not a fan of interviews that include quizzes, mini code assignments or brain teasers, but I tend to think it can include a "talk through how you'd approach this problem" kind of question. There'd be no right answer... it's just a great way to see what logical steps someone would take to break down/isolate and resolve a problem.
10/07/09 @ 16:01
Comment from: barryb [Visitor]
***--
Only basic maths is required for most situations. Far more important is the ability to think clearly, so agreement with the point about philosophers writing good code. Perhaps even more importantly to focus on what it is required to be done, than an amazing technical solution with todays latest hot new technique, applied out of context.

Thinking clearly applies not only in writing the code, but in approaching resolution of problems. Too many programmers leap into debugging with no forethought, when a cursory thought process and code review could have spotted the bug or guided to a more appropriate start point.

So perhaps programmers need to be able to read as well?

10/08/09 @ 04:34
Comment from: Jasper [Visitor]
*****
If a person doesn't even know how to do very basic math things like this, which they should've learned in school when they were 12 or so, then that person is absolutely not suited to be a programmer. Such a person should stop programming immediately and pursue a non-technical career that doesn't require them to deal with numbers.

In fact, I find it astonishing that people who don't even know very basic math have ever become programmers. If you don't even have the smallest bit of talent in math or technical things, then how and why did you become a programmer?
10/08/09 @ 04:57
Comment from: Gilberto [Visitor]
The youngster "programmer" I heard was 7 years old. A 10 years old girl from Pakistan was the youngest certified Microsoft expert a few years ago. 14/15 years teenagers are compiling their own kernel right now, all around the world.

So, do we need a degree to become a programmer ? Not in my world.

Do we need to know basic math as programmers? I think so, at least for professional programmers.

Math is a business requirement, not a requirement to be a (good) programmer.

We'll need basic math to get a job. We'll need advanced math to build sophisticated games, but it's a business requirement, it won't make us better programmers.
10/08/09 @ 08:12
Comment from: george mauer [Visitor]
Some contractors told me: this density is lbs per gallon but in order to do this calculation we need gallons per pound. We have searched the entire internet and no function to convert between the two exists. We have concluded it to be impossible.

We are no loger with that company.
10/09/09 @ 07:17
Comment from: paranoiq [Visitor]
for anybody, who dares to do programming without a basic knowledge of mathematics i have a message: http://piv.pivpiv.dk/

"nother example is ORM....people hate writing queries" - generalization stinks. for example i love writing queries and hate ORM :]
10/09/09 @ 08:25
Comment from: Dude [Visitor]
The scary thing is they didn't explain why they wanted to reverse the sign. Problems don't exist in isolation. Maybe they only wanted to do it for negative numbers in which case |ABS| would be appropriate. Its not safe to multiply by -1 in this case.

As for this effort from Jason, it will only work for making positive numbers negative. Its not even an anti-ABS because at least ABS makes no change to positive numbers. Credit for thinking about it a little.
//
numberToInvertSign = numberToInvertSign - 2 * numberToInvertSign
//

The problem with the question is not that they are stupid or don't know maths, its that people are too quick to post questions for which a quick googling on a maths website would provide the answer.
10/11/09 @ 05:13
Comment from: CreativeSmarts [Visitor]
*----
Sorry. I am one of those people that you all are lambasting. I hate math. Have since the day I was born. I failed it in almost every grade I took it. However I have a great creative mind and somehow I seem to figure things out even if it takes me a couple of hours longer to do things than my programmer buddy next to me. I don't think you have to know how to do math - you just have to have the right resources to show you how to do the math you need to do. Whether that is a textbook, googling it, copying it from code you've used before or whatever. As long as you can get the job done, who cares?
10/11/09 @ 19:24
Comment from: Chris [Visitor]
*----
I learned programming before math. I managed to out program all my little friends at the time, including the math geeks who were in high math classes and a year ahead. Not only that, but by learning programming I was able to better understand math. For someone who learns math, functions/procedures are more like f(x) but for someone who learned programming first f(x) is like a function.

Also in my professional career I don't use advanced math. I don't use more than algebra. I know for engineering/video game development/systems simulation more advanced math is involved. But in a normal business basic algebra is fine. Usually plugging in numbers for financial equations. Even advanced algorithms are not required with most of the libraries pre-written. Basically business logic is mostly a series of decisions. The most advanced math I use is the occasional topological sort because it is useful for figuring out the order to do things given a bunch of dependencies (ie the order to perform a sequence of calculations that a user specifies).

And on logic, if you need a course on that then you have problems. and = traditional definition of and, both items or it is false. or = traditional definition of or (a, b, or both). XOR is a little new but still easy enough to master with a knowledge of and/or. Basically the truth tables for these operations are intuitive. After that, without anything else most SQL queries are easy and intuitive too. Add some set theory such as union and intersection and you are all set. I learned SQL long before I ever had a discrete mathematics course, it was easy. And I wrote some queries that are still used at my first internship even today...and I had that job before my freshman year of college.

Anyway you people need to stop with the holier than thou get off my lawn stuff, it makes me sick. Also on the guy with the degree in music, I had heard that from more than one person that music majors often make great programmers. And to the guy who says everyone needs a degree in science/engineering here is your counterexample. Also there are a lot of non-degree programmers who are absolutely great. I know one guy who dropped out of college due to failing out who could outprogram the entire class. His programs were the stuff of legends, but unfortunately his exam scores not...

And on negating, I would think it is more efficient to do 0 - number. Generally addition/subtraction have a cost of log(32) while multiplication has a cost of log(32)^2 when using 32 bit ints. Now if you are using higher bits it will take more time. If you are using arbitrarily long numbers, this makes a difference....What if they are 10000 bits or something. your Pi computation may slow to a crawl.....

But I think it depends what you want to do. Graphics programmers will be doing all sorts of advanced math, linear algebra, interpolation, etc... so will someone making a nuclear simulation. But the guy at a normal business probably just basic algebra. Even accounting software will mostly be plugging numbers into standard equations. Although it does help to have some idea of the asymtotic complexity of your library. ie is that list you are using o(n) per operation or lg(n)? Then if you run into performance problems you have some ideas for improvement. I did take someone's o(n^3) algorithm and turn it into O(nlogn) for a big performance improvement. If it wasn't taking so long I probably wouldn't have bothered with it....
10/12/09 @ 11:29
Comment from: jason II [Visitor]
***--
This is not so much about math as human nature. Most problems have many answers but rarely do we arrive at the simplest solution.

Apply simple refactoring techniques to these code samples and you will arrive at your suggested final solution.
10/13/09 @ 14:40
Comment from: Emtucifor [Member] Email
Dear Mr. Dude,

You said:

> As for this effort from Jason, it will only work for making positive numbers negative.
> Its not even an anti-ABS because at least ABS makes no change to positive numbers.
> Credit for thinking about it a little.
>
> > numberToInvertSign = numberToInvertSign - 2 * numberToInvertSign

Are you sure you want to stand by your claim that this only works for positive numbers? Right now you're providing a shining example of someone who isn't too strong at that math stuff. Look:

f(x) = x - 2 * x
f(x) = 1x - 2x
f(x) = (1 - 2)x
f(x) = -1x
f(x) = -x

His function works just fine for positive or negative numbers, dude. Er, Dude.
03/21/10 @ 21:01

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)