If you can read this, either the style sheet didn't load or you have an older browser that doesn't support style sheets. Try clearing your browser cache and refreshing the page.

(Telegraph)   How to code, step one; learn to ^c^v   (telegraph.co.uk) divider line 23
    More: Advice, algebra, baking sodas, maths, digitizations, calculus  
•       •       •

6527 clicks; posted to Geek » on 09 Dec 2012 at 5:25 PM (1 year ago)   |  Favorite    |   share:  Share on Twitter share via Email Share on Facebook   more»

Voting Results (Smartest)
View Voting Results: Smartest and Funniest

Archived thread
2012-12-09 05:56:09 PM
3 votes:
If you're writing a database LOB CRUD application? No. Any reasonably intelligent person could accomplish it with today's tools.

If you want to really "code", you need to at least understand the basics of Algebra.

If you're writing 3D games, you are going to need to need to understand trigonometry.

If you're writing financial software, you are going to need to know a few things about statistics.

If you're writing a spam filter, a good understanding of Bayesian probability would be a big help.

Programmer translate ideas into code. If we don't understand the source material, we cannot properly translate it.
2012-12-09 01:07:29 PM
3 votes:
And guess in which class you'll be learning the logical thinking skills that allow you to handle all those if's and then's...
2012-12-10 03:11:24 AM
2 votes:

Jay CiR: Heh,

I started teaching myself PHP and ASP just because I had some web-based ideas, and I wanted to figure out how to make them happen. Since then, I've been working at coding more efficiently, whenever I can. It's been a great learning experience, but, having started in, and working only within, a web browser-only medium (I already had several years of HTML under my belt when I started with PHP and ASP), and speaking to other developer friends about some of the work they do (Ruby on Rails, for one, comes up a lot), I feel like I'm missing out on something (actually, a lot more than just "something").

Any recommendations for a curious beginner like myself, looking to break out of web-oriented programming?


(Keep in mind that I'm a college senior with a couple internships, so 1)the older guys might have better advice, and 2)this all comes with a big "In my limited experience" caveat)

My experience has been that there are 2 camps of programming languages (and I'm generalizing like MAD). Scripty (of which web is a subset, so this is your LISP, Python, Perl, Ruby (on rails), JS, HTML, etc.), and Heavy (mostly languages that evolved from C, so C/C++, JAVA, C#, etc). Scripty is usually an interpreted language that runs inside of something else, is extremely flexible, weakly and dynamically-typed, and very agile. Heavy is usually a compiled language, with odd constraints because of that. Heavy also lends itself well to big, carefully-architected projects based around OOP. .They're also way less flexible (Try doing a Ruby Hash in C++, for example). They both work, and they both have different metaphors, and canonical ways of writing code.

You already have a fairly strong basis in the scripty stuff, but most of the not-web stuff is written in heavy languages. So (and keeping in mind that I'm giving you the same advice as a freshman, who knows nothing about coding, so you may already know some of this):

0) Get out of the IDE's for at least steps 1-3.

Pull up a Linux VM (Mint is quite good and easy to learn), write in Emacs/Vim (And there will be an UNHOLY flamewar about which of these to use. I use vim/gvim because my mentor used vim. If you use vim, pull up vimtutor in the command line FIRST to learn WTF you're doing. Either way, my personal advice is to make your desktop background and screensaver lists of useful commands for your particular editor until you've learned all the commands), compile with command line gcc/g++ and makefiles, and run from the command line. When you start using malloc()/dealloc() or new/delete, run everything in Valgrind to make sure you have no memory leaks. Do it yourself, so you know what's going on.

1) Learn a couple of heavy languages.

C/C++ would be my preferred one. C++ syntax sucks a lot, but having to explicitly use pointers and references vs. values, overload operators when necessary, and manage your own memory is really critical to understand what is going on at a low level, and JAVA/C# abstract a lot of that stuff away as part of being managed code (esp. the all-important memory management).

Write some pure C on the side to do some procedural stuff (It really is a different paradigm than OOP), realize just how dangerous pure C is, and how awesome C++ with the standard library (esp. C++ 11 with all the new stuff and extra standard libraries as part of the language) really is (std::string vs. null-terminated char *, vector vs. array., templating vs. unsafe void * casting, etc).

As part of this, learn how to use const properly in C++. There's like 4 places const can go in a function definition, and it's REALLY, REALLY HARD to kinda use const, because the compiler tends to throw a fit (that you often can't do a thing about or even figure out what it's yelling at you about in the first place), so you either don't use it at all, use it correctly from day 1 of your project, or devolve into a giant muddle of calls to const_cast.

2) Learn pointers. Know Pointers. Love Pointers. (Start using C here)

I had 15 different interviews this fall ask me the question about how to reverse a singly-linked list (which is really easy if you get pointers, and really insane if you don't). Learn what the difference is between Clock * c1ptr = c2ptr, and Clock c1 = c2; Be able to think at multiple levels of abstraction easily. Be able to avoid segfaults (and remember that segfaults are a good thing. The alternative is messing up your heap and stack, and you NOT KNOWING, and getting very, very subtle bugs as a result).

You either can do this or you can't. If you can't do this, give up and go back to web programming, because you'll never be a good "heavy programmer" since EVERYTHING is based around this.

While you're doing this, learn Angry C (also known as "WTF" C). Know all the stupid tricks about Operator Precedence and how to use them. Know why "while(*dest++ = *src++);" copies a null-terminated c-string. Use the ternary operators. Even better, use nested ternary operators (1 == x ? foo() : 2 ==x ? bar() : baz();). Put assignment in a while loop's condition (And then after you do that by accident a few times ('=' vs '=='), ask yourself why I did 'value' == 'variable'). Use case fallthrough in interesting ways. Try and do as much as possible in one line of code. (Don't keep doing any of this beyond this step though. Even if it works, your fellow programmers will lynch you. Think of it as a rarely-used tool in the toolkit. Just because you CAN use the comma operator or Duff's Device doesn't mean you SHOULD.).

I'd also write a couple of type-independent data structure implementations using void * just to learn how to deal with casting and the utter lack of type-safety.

3) Learn algorithms and data structures. (Start using C++ here)

If at all possible, do this in a formal setting, like a college course where you have to implement various data structures on your own.

For algorithms, LEARN BIG-O. Learn why O(1) vs. O(lg n) vs O(n) vs. O(????) matters. Know the Big-O time and space complexity of every algorithm you run across. Know how to at least kinda guess at the Big-O of an algorithm. KNOW ALL THE SORTS (lot of interview questions here. Know quicksort, merge sort, insertion sort at minimum, and be able to crank out code on command). Learn how to optimize your code for time and/or memory.

For data structures, write your own singly-linked list, doubly-linked list, vector, map, set, unordered_map (also known as hashtable), and deque classes in C++ with pointers and manual memory. Make them all templated, and make them all have iterators. Learn their Big-O's for lookup, insertion, and removal, and know what that makes them good for. EVERY SINGLE INTERVIEW I had at companies that I would have wanted to work at had AT LEAST 1 question that was "Tell me about Data Structure X". The company that I accepted at had a 2-hour interview (as part of an all-day interview) that was nothing but me and a guy with a PHD in data structures shooting the breeze, and filling up 2 separate whiteboard walls with scribbles, notes, thoughts, etc. Data structures are utterly critical.

4) Learn OOP.

Inheritance; multiple (and diamond. Even though this is frowned upon, if you know how to make it not-screwy, it's a valuable, if seldom-used tool) inheritance; composition vs. inheritance; public, protected, private; abstract classes; virtual functions; dynamic casting, all that good stuff; This is the toolkit that you'll be applying when you...

5) Learn software architecture.

You probably already know this from your web experience to a certain extent. Learn the design patterns you don't know (Singleton, Factory, and MVC are probably your big ones here.). Know when to use them, what they're good for, etc. Know how to decouple a class from another class, and have discrete pieces of functionality in separate places in the code. BEST CODE IS NOT FASTEST CODE. BEST CODE IS MAINTAINABLE AND EXTENSIBLE CODE. Also, at some point in here, learn the various std::???_ptr classes. They're really cool, really powerful, really dangerous if used improperly, and this is about the point where you'll really stop having a single point in the code where you can say "Yeah, I'm done with that pointer, and it can be deleted there".

6) Possibly at some point, learn about multi-threading and/or assembly.

For multithreading, Locks, deadlock, livelock, the up and downsides of pure and readwrite locks. I wouldn't necessarily recommend writing your own threading library like I had to for class, but just learning the basic concepts, and how to use the canonical library for your preferred language probably isn't a bad idea.

I've honestly never, ever had to learn or use actual assembly. I had a class with a minimally Turing-complete assembly language for which I had to write several C implementations that implemented various versions of the architecture, and they taught us about pipelining (aka: Why Lots of Jumps are Bad), and some of the basics of architecture and microarchitecture, but you're probably going to be high enough that it's not really a huge concern. Now if you want to write compilers, go the embedded systems route, or do serious, serious optimization work, learn it and learn it well, but there are millions of programmers who have never used (or even heard of) assembly, and are totally fine, good, competent programmers.

7) When you're done with C++, go over and learn either C# or Java.

They remove a lot of stuff from C++, make the syntax a lot nicer, and add a couple things I really like. They also:
*Make everything an object, and pass around references, so that there are no pointers, period.
*Don't require manual memory deallocation, so that you can new() to your heart's content.
*Remove multiple class inheritance, but add these things called Interfaces, which are basically fully abstract classes.

This does some odd things to the metaphors that C++ was allowing you to use ("I am a" vs. "I can do"), which does some weird things to "the correct way of writing code" and knowing what these changes are is critical. It's a subtly different way of thinking. Nothing like the huge transition you're making from the scripty side, but it's there.


The definitive C89 book: The C Programming Language, 2nd Edition (called Kernigan and Ritchie): Wikipedia Amazon

The definitive C++98 Book: The C++ Programming Language (3rd Edition) by Bjarne Stroustrup: Wikipedia Amazon

Note that new editions of the above books are coming out soon, because we just got new versions of the languages. (C11, and C++11)

The definitive Design patterns book: Design Patterns: Elements of Reusable Object-Oriented Software (also called Gang of 4): Wikipedia Amazon

My class's algorithm book: Introduction to Algorithms, CLRS: Wikipedia Amazon

The class I took that was really good at teaching C/C++/software architecture (and is a requirement to get looked at by Google) was EECS 381 at the University of Michigan. I believe this link is open to everybody, and for the next week or so, all the projects are up so save it all to your computer (The professor puts the projects up as the semester goes on). Project 1 is C, Project 2 is C++ without the standard library (You reimplement std::string and std::list), Project 3 is the standard library, and "algorithm" (You're not allowed to use loops at all), Project 4 is architecture, project 5 is smart pointers that auto-delete memory, project 6 is the final exam. Also, since I took it, I believe that he rewrite the course for C++11 (Link)
2012-12-09 06:34:42 PM
2 votes:

Happy Hours: No - copy/paste is not a programming method.

I've been saying this for farking years.

If you find yourself doing a lot of copying and pasting maybe you just call a function.

If you write a block of code once, consider making it a function.
If you write a block of code twice, you must make it a function.
If you write a block of code three times, we should consider firing you.

I probably botched the quote a bit, but basically the same sentiment.
Copy/Paste is design patter. A terrible terrible design pattern that results in terrible, un-maintainable software.
2012-12-09 06:00:28 PM
2 votes:
Been in software development for over 20 years.

There's a lot of copying stuff from elsewhere now, and you'd be daft as a developer to build your own AJAX-based grid rather than using jQuery and jqGrid.

BUT do you know the difference between local and server-side filtering? How long that request is going to take if you fetch all results in one go vs doing filtering and paging on the server side? What indexing you need to put on the table? How to write and secure the server side JSON request? How to validate the request? Do you know how to tell which plugins are worth using?

The worst way to teach people is with "here's a chunk of code, paste it in". The right way is to teach people to code using a blank sheet of paper where they learn all the fundamental stuff like loops, decisions, classes, SQL. Then move on to HTML and Javascript. And once you've done that, then you start telling them about all the shortcuts to doing the stuff you've taught them.
2012-12-09 05:36:54 PM
2 votes:

doglover: What I haven't had since 1998 is a code environment.


As a self-taught coder, I stole code. Not so much to steal it steal it but, more to figure out what coders thought and did and how they arrived at their conclusions. Bottom line, I was the smartest coder who ever lived.

Until I went to university and starting taking higher-level math classes. That's where I learned that easiest sort is also the worst sort. And, this twisted, nobody-would-have-ever-thought-of-that sort was the best sort... unless the list was already sorted, in which case, it's right up there with the worst sort.

And, there's all this big O stuff that goes along with it and then there was the proof-writing class. I could never *read* proofs before. Now, I have to write them? And, holy crap, you mean that there's actually something *to* all these proofs and why things go fast and why things go slow and why crypto algorithms are provable weak unless they're provably hard and how some 14 year old has a clever way to bypass your provably hard crypto algorithm....

and, that's when I discovered that I wasn't the smartest coder who ever lived.

But, I'm still pretty damned good and thank goodness for all those math classes or I'd still be writing bubble sorts.
2012-12-10 04:35:01 PM
1 votes:

redmid17: what if I'm copying and pasting my function?

The entire function, or the function call? If you are copying the entire function, I would stop and ask why. Maybe that should be encapsulated within another method.

If it is just the function call, I would still type it out. That way you could catch any errors (or not propagate errors) in the parameter list. If you are copying it because only one parameter is changing, why not determine the parameter ahead of time and call the function. Either way, copying and paste should be a warning flag. Granted, there may be time when it is appropriate. But you should always stop, take a breath, and ask yourself if there isn't a more efficient, less error prone way.

Taking a few extra minutes to code can save a few hours of debugging.
2012-12-10 04:07:14 PM
1 votes:
True story....

A department had a series of 'weekly reports' they'd generate and send up to the senior staff. It started off as a small Excel file, but over the years got bigger and bigger. Eventually it took two people most of every Monday to generate this Excel file. They did everything by hand and they always seemed to screw up something (that always went unnoticed).

They had an intern come in who had done a vague idea of what VBA was. The kid sat down with them and wrote some really, really ugly VBA macros that did the same thing. He worked on it for the better part of a month. His script ran in 15 minutes and took over the keyboard, but in 15 minutes, the report was done and it was always done correctly.

Fast forward 8 months. They wanted a change made. The intern was gone so they sent in an official development task (like I said, big company so everything needed to be a formal request to be approved and prioritized). The internal development team cited 10 standards that the VBA script didn't comply with. The code was copy/pasted/hacked together. That wasn't good enough. They were going to design a PROPER system. Lord knows, it's not like anyone has ever sat down and decided to make a 'reporting system' before.

They spent months, many months, designing this system. It was going to be the end-all, be-all of reporting (again, what an original idea!). I might be wrong on the details, but I think it was an SQL database they put together to populate the data, then an application (I think in VB) that would parse the data feed into the database, then they created a task in the scheduling system that would run the import job and alert them if it failed, then they wrote stored procedures to perform the calculations the Excel file used to do, then they wrote pages of Crystal Reports that would pull the data from the database.

Naturally, they made it so the reports looked nothing like the original report; and the higher-ups didn't like it. And bugs and mistakes were made along the ways, and releases were pushed out and sent to the QA department and all that jazz. Good times.

Eventually, they had it all working, including the small change the intern could have done in 4 hours. It took them over a year and endless man hours. But it was done 'right' by real 'Software Engineers'. And life was good. The new system had some problems - before if the CSV file showed up late, they'd just start the report late. Now they had to get someone with access to the job scheduling system to kick off the import job after it's initial attempt had timed out. And, it was fairly common for there to be bad data in the data file, instead of '71.81' they might get a value of '7181'; before they'd just fix it. But now they couldn't. If they knew SQL (and none of them did) they could have updated it in the database, but, 'officially' they needed to submit a trouble ticket to the DBA team who could update it on their behalf.....but that could easily take 4-5 hours before someone would look at it.

But okay, still, it was a working a system.

Then, one day, for reasons unknown to me, the senior VP asked for the .xls file. I guess he'd done it years ago and wanted to see the original Excel file and do some work with the numbers. Nobody had mentioned that the new system wouldn't generate a finished, formatted Excel file anymore. And that's what he wanted.

And even though it was months since he could do that, once he knew he couldn't, it was a high priority issue. I kid you not, the development team said, 'Oh yeah, we can do that' and started working on a batch job that would run after the import job that would pull data from the SQL database and use some Excel interop library to generate an Excel file.

I've never tried to create an Excel file from inside VB, but I guess spitting out data was easy enough. Even though they'd calculated all the values inside the stored procedures, the VP wanted to see the formulas in the Excel file - so they actually re-created all of the logic in the Excel file! Again! Only now it was in a VB program that created the Excel file.

What wasn't easy enough was getting all the cells colored the correct way and alignments and resizing and all the crap the ladies used to do by hand each Monday morning. I guess they got 'most' of it; but couldn't do all of it and ended up using a VBA macro to do it. Seriously. So, in the end.....

They had a task scheduling system that would kick off the data import VB application that would feed the data into and SQL database that the Crystal Report client would use to generate the report with the data from the SQL stored procedures that would be compared against the Excel file that the Excel file creation tool would generate. Then, when the numbers matched (and they always matched since they were generated the same way) someone would run the VBA formatting macro on the Excel file so they could include the Excel file along with the near identical looking Crystal Report generated PDF (I think it was PDF).

That was a very depressing place to work. But hey, at least we didn't have any cut-and-paste code cowboys doing simple things effectively.
2012-12-10 03:49:30 PM
1 votes:

un4gvn666: I'm on my last 2 weeks of Intro to Java for my pre-reqs, before I move into my first year of CS. I finished Intro to C++ last semester. Needless to say, the comments have definitely been eye-opening. Thanks, guys.

Keep one thing in mind as you roll down the CS path. If your school's anything like my alma mater, the CS guys will look down on the Management Information Systems guys in the College of Business, for a variety of reasons.

Just remember, once you graduate, if you want the latest and greatest toys, there's something to be said for having someone around who's a geek, but who can also make the business case for the latest and greatest tech. Someone who can interpret code, and also speak MBA.
2012-12-10 11:19:11 AM
1 votes:

vossiewulf: mcmnky: *facepalm*

Logic is Math. Rantity rant rant...

I didn't say NO math, I said no math greater than third grade. Or maybe fifth grade. I know a zillion very logical thinkers who manage to do so without the use of differential equations, I guess you are unlucky. And you don't need trigonometry to profile code and based on experience, knowledge of what it's doing, and what it's supposed to do, know whether it's fast enough or as fast as it could be, and then drill down on the slow functions and improve them.

Dunno guy, I manage a large group working on code that generates revenue with numbers starting with a b, everyone is quite pleased with the quality and efficiency, and none of my guys needs to take a cosine of anything. The BI guys, that's a different story.

If you're working on code that's supposed to analyze complex data, involves physics, or any other number of math-intensive applications, yes you need good math guys. But as I said originally, there are large sectors of the coding world where that isn't the case.


Trigonometry is good for graphics, Algebra is good for understanding basic equation functions, but what every coder needs to know is Discrete Structures.Knowledge of recursion, NP complete, induction, etc... is vitally necessary for every code. All coders that I have ever encountered who could not even begin to explain the most basic of finite mathematics were always the worst coders I ever had the misfortune to work with.
2012-12-10 10:28:53 AM
1 votes:

DeaH: As a person who writes those requirements...

Well, then I gotta ask, then why can't the customers just take the specifications directly to the software people, huh?
2012-12-10 07:32:50 AM
1 votes:

rosebud_the_sled: //SQL is not programming

I agree, but there are some SQL statements of such incredible length and complexity that I have dealt with that it's pretty close once in a while.


(Keep in mind that I'm a college senior with a couple internships, so 1)the older guys might have better advice, and 2)this all comes with a big "In my limited experience" caveat)

A lot of that stuff you mentioned is unnecessary depending on what type of programming job you're going after. There are thousands of business logic programming jobs out there that not only will you not be asked in an interview about pointers or data structures, but the interviewers themselves will find it hard to recall how to manage a linked list. C# and VB.Net type jobs with a lot of db calls are what I spent years doing and it was mostly pretty straight forward. OOP is used, but often not extensively and at times its usage is contrived in business apps.

Really for most businesses I worked with they never touched C++. The time it took for development was too costly and with almost no pay off for type of applications they wanted.
2012-12-09 09:53:28 PM
1 votes:

I didn't say NO math, I said no math greater than third grade. Or maybe fifth grade.

If you think the pertinent math here is diff eq and trig, it's really sounding like you have extremely limited experience. Those jobs are there, but honestly, they tend to result in bad code. Maybe you're that one in a million.
2012-12-09 08:59:38 PM
1 votes:
Math? Completely worthless for programming.

Now if you'll excuse me, I need to get back to copying this bubble sort algorithm for my new Google search replacement.
2012-12-09 07:26:32 PM
1 votes:

midigod: FTA: "So in most cases you can see that the hard maths (the physical and geometry) is either done by a computer or has been done by someone else. "

Wow, what great career advice. "Don't worry, someone else will do the hard part." Holy crap.

Although that quote IS an oversimplification, it's called "not re-inventing the wheel".
2012-12-09 07:13:03 PM
1 votes:
Actual mathematics (meaning proofs, theory, etc. and not just arithmetic) is closer to programming than pretty much anything.
2012-12-09 06:52:05 PM
1 votes:


Came here to say something like this. Taking other people's functions doesn't teach you a goddamned thing.

Well, not if you stop there. If you take someone else's code, then start reading and modifying it though...
2012-12-09 06:38:11 PM
1 votes:
Strictly speaking you may not use math very much in most programs, but the mental skills used for math are similar to the ones used for programming. If you're bad at math, you're almost certainly going to be bad at programming too. Don't despair though. There are plenty of bad programmers out there. Their lack of skill hasn't stopped them and it shouldn't stop you either.
2012-12-09 06:19:26 PM
1 votes:
No - copy/paste is not a programming method.

I've been saying this for farking years.

If you find yourself doing a lot of copying and pasting maybe you just call a function.
2012-12-09 06:15:10 PM
1 votes:

What are you going to do with all that coding knowledge when the server physically fails?
shiat, what is the average person going to do with coding knowledge period.

///last shiat I programmed in was BASIC...not visualBASIC or QBASIC
2012-12-09 05:33:19 PM
1 votes:

doglover: I would like to learn how to code.

What I haven't had since 1998 is a code environment. I don't know how to compile and then debug without a program to do so. I also drag and drop elements like in C#.

Look into the "Eclipse" IDE
2012-12-09 05:29:18 PM
1 votes:
Back in my day we learned to code by adding cheats to nibbles.bas. And we liked it.
2012-12-09 01:33:57 PM
1 votes:

What being good at maths might look like.
Displayed 23 of 23 comments

View Voting Results: Smartest and Funniest

This thread is closed to new comments.

Continue Farking
Submit a Link »