PDA

View Full Version : Learning programming



Eon
2009-10-27, 09:52 PM
So, i finally decided to try out programming to see if this was really the field i want to go into in a few years. Is there any good advice, good programs, do's and don'ts i should know?

I downloaded the C# express edition from Microsoft from Microsoft. I don't illegally download

Please?

also i hope this is in the right place/not already a thread. sorry otherwise :smalleek:

Jack Squat
2009-10-27, 09:56 PM
I'd choose an easier language to start out with. Most places I know of start people on Java, C++, or BASIC/Python. Not that C# is bad, but I believe it has a steeper learning curve. In full disclosure, I only have learned C and C++, and am out of practice in both.

All that aside, this site (http://www.csharp-station.com/tutorial.aspx) seems like it'd be a good place to start with C#.

Eon
2009-10-27, 09:57 PM
yeah, i was looking for C++ but i couldn't find it.

Jack Squat
2009-10-27, 10:04 PM
this (http://www.bloodshed.net/devcpp.html) is supposed to be decent. I did all my programming on Linux, and haven't tried anything out since I left the College of Computer Science.

Going off of a Google search, there's also this site (http://www.thefreecountry.com/compilers/cpp.shtml) and this (http://www.microsoft.com/Express/VC/) (though it's generally a pain to use).

MethosH
2009-10-27, 10:06 PM
http://www.microsoft.com/Express/VC/

Honestly... I don't think jumping into object oriented is the best way to start... But maybe that is just me :smalltongue:

Icewalker
2009-10-27, 10:10 PM
I learned a bit of C++ and java in high school, then learned Python during an internship. Python is FANTASTIC, and extremely intuitive and easy by comparison. It's certainly not unreasonable to start with something else (C++ is a better choice than anything earlier though, I'd say) but Python really is a great starting point. Or, point, period, it's not like it's terribly limited compared to other languages.

AstralFire
2009-10-27, 10:11 PM
People still learn BASIC as a starting point?

Jack Squat
2009-10-27, 10:11 PM
http://www.microsoft.com/Express/VC/

Honestly... I don't think jumping into object oriented is the best way to start... But maybe that is just me :smalltongue:

Just because it's object oriented doesn't mean you have to deal with that right off the bat. Everyone's gotta learn scan, print, functions, and loops before you get into the cool stuff.



People still learn BASIC as a starting point?

There's some places that still teach FORTRAN to start off with. But yes, the university I go to has kind of a precursor course that's BASIC.

Eon
2009-10-27, 10:14 PM
Just because it's object oriented doesn't mean you have to deal with that right off the bat. Everyone's gotta learn scan, print, functions, and loops before you get into the cool stuff.

scan? print? functions? loops? i think i know what they mean but... i guess i'll learn soon :smalltongue:

AstralFire
2009-10-27, 10:14 PM
Printing is sending text to screen.

Jack Squat
2009-10-27, 10:21 PM
scan? print? functions? loops? i think i know what they mean but... i guess i'll learn soon :smalltongue:

heh...I remember when I was like that.

scan is reading input in (another name is read), print is outputting data (also called write). Functions are just what something is contained in. You can embed functions to separate jobs in programming, but that starts to get into object-oriented programming. Loops are used to repeat a command more than once (while a condition is true).

This is all probably going to be completely over your head, but once you start doing things it'll come to you.

MethosH
2009-10-27, 10:26 PM
This isn't the first time a thread like this one appears... And won't be the last... I'm thinking of starting a "Learning basic programming in the Playground" thread. Where we could share/write tutorials and reply to questions from the nb. What you guys think?

Jack Squat
2009-10-27, 10:28 PM
I'd be for it...might even learn something.

Dunno how long it'd last though.

MethosH
2009-10-27, 10:34 PM
http://www.giantitp.com/forums/showthread.php?p=7204606#post7204606

Done : )
I'll write something more tomorrow. Gotta go now.

blackfox
2009-10-27, 10:55 PM
I learned on C++ when I was in middle school and then again on Java later. Haven't ever programmed in C#. I'd recommend Java for a beginner, although mostly because the API is so pretty.

Tirian
2009-10-27, 11:07 PM
It sounds like a good thing. To be honest, these resources are already on the web, though. It might be better to just point someone over to the xkcd forums which have FAQs on where to go to learn programming from first principles.

In theory, you can learn any language first. I went BASIC -> Pascal -> Lisp -> C++ -> at this point you can learn any language in a weekend. But, back in my day, there were fewer languages to choose from. :vaarsuvius: Nowadays, the conventional wisdom is that Python is the best first language, and I am largely in agreement with that. There is certainly no lack of books and online resources that are happy to teach Python to someone who is completely new to programming.

Eon
2009-10-28, 04:03 PM
are you trying to tell me to choose a different language to start with?

Jack Squat
2009-10-28, 04:27 PM
are you trying to tell me to choose a different language to start with?

I think he's just saying that Python is generally considered to be easier to learn. Plenty of people have learned C-based first, and that's how it's taught most places, so yours isn't a wrong choice. It's just not the easiest route out there.

pendell
2009-10-28, 04:35 PM
Guys,

I'm a C++ developer with 15 years experience, and I tell ya: Stay the heck away from C++. I'm having a devil of a time finding work. The world has gone to J2EE/Java, C#/.NET, and some Python.

I recommend going directly into C# and avoiding C++ -- there are all kinds of C-isms in C++ that are bad holdovers from the 1980s. It won't help you land work, and it will teach you bad habits.

As to specific tutorials -- well, if you're learning java, you can get it and tutorials free from java.sun.com. I can't find a good one for C# at the moment, but google can probably help you quite easily.

Respectfully,

Brian P.

Eon
2009-10-28, 04:36 PM
Guys,

I'm a C++ developer with 15 years experience, and I tell ya: Stay the heck away from C++. I'm having a devil of a time finding work. The world has gone to J2EE/Java, C#/.NET, and some Python.

I recommend going directly into C# and avoiding C++ -- there are all kinds of C-isms in C++ that are bad holdovers from the 1980s. It won't help you land work, and it will teach you bad habits.

As to specific tutorials -- well, if you're learning java, you can get it and tutorials free from java.sun.com. I can't find a good one for C# at the moment, but google can probably help you quite easily.

Respectfully,

Brian P.

I found it at Microsoft's official website

EDIT: also, does anyone have a spreadsheet or something of the sort with basic commands i can use?

Jack Squat
2009-10-28, 04:52 PM
Guys,

I'm a C++ developer with 15 years experience, and I tell ya: Stay the heck away from C++. I'm having a devil of a time finding work. The world has gone to J2EE/Java, C#/.NET, and some Python.

I recommend going directly into C# and avoiding C++ -- there are all kinds of C-isms in C++ that are bad holdovers from the 1980s. It won't help you land work, and it will teach you bad habits.

As to specific tutorials -- well, if you're learning java, you can get it and tutorials free from java.sun.com. I can't find a good one for C# at the moment, but google can probably help you quite easily.

Respectfully,

Brian P.


Yeah, That's what I keep hearing (Some guys at ORNL were actually laughing about no one using C anymore, and the entire CS140 class (Data Structures in C) overheard.

I plan on teaching myself Java when I get the time, but since I'm not planning on going commercial, rather make it a hobby, I don't think it matters too much what I use rather than how well suited for the job it is.



I found it at Microsoft's official website

EDIT: also, does anyone have a spreadsheet or something of the sort with basic commands i can use?

Search online for a library. C++ has one at http://cplusplus.com, C at http://www.cs.cf.ac.uk/Dave/C/ and more will turn up with a search - those are just the ones still in my favorites.

Jade_Tarem
2009-10-28, 05:02 PM
Software Engineering Major here (Senior year undergrad).

I started with Java, then C++. This year I've been required to work in C++, C, VHDL, Python, Prolog, Scheme, and will eventually learn Smalltalk, although those last three are not "mainstream" languages and were (or will be) only studied briefly as part of a Principles of Programming Languages course.

Python has been the easiest for me to pick up on so far, but that was after 3 years of Java and C++, so I don't know how good it is to start with. It does seem more intuitive, and you won't wear out your {}; keys as quickly, so maybe popular opinion is correct on this one.

As for tips?

1) Find a good programmer, and get a book recommendation from them. A large number of "Learn how to program in X" books out there are garbage, but there are also a number of good ones written by very bright people with decades of experience.

2) Programming is a skill, and like any other skill, practice is what makes you better at it, once you've learned the basics from another source (like a good book or a better programmer).

3) You will come to know the depths of true frustration in the course of your learning, and you may come to the mistaken conclusion that your compiler hates you. When this happens you should take a deep breath, remind yourself that the computer is a machine and therefore isn't a spiteful **** at all, and restrain yourself from putting your fist through your monitor. That's not where the brain of the computer is anyway.

4) Build programs in stages. Figure out how to do something, make it work, then build on that. If you get stuck, at least you can go back to what worked and try again.

5) Try to make your code as readable as possible. Give variables meaningful names like mainCounter or inventoryNumber, which is much easier to read than q, x, and zz, especially when you write larger programs with dozens of variables and quickly exhaust everything in the English and Greek alphabet. It will save you and anyone you ask to help you with your code a lot of frustration in the long run.

6) For those languages that have {} to note compound statements, there are two ways of positioning them.

The unwashed heathen way:

if (you == unprofessional){
....cout << "This is how you write code.";
}

And the One True Way:

if (you == suaveAndAwesome)
{
....cout << "This is how you write code.";
}

Alright, technically both ways are correct, and this is something of a holy war among programmers that might make some people here a bit ticked, but I've shown you the light early on to make sure you aren't seduced to the dark side. :smalltongue:

7) Realize that you're essentially learning new languages - it's going to be pretty hard at first, and you'll wonder about going into a different and less frustrating career field, like giving suppositories to rabid tigers. All I can say is that you should give this a solid chance before you give up on it.

8) Also realize that this field is enormous. However much you learn, there will always be more. What's more, the field is ever-changing. What's held as the gospel truth at one point may be laughably obsolete very soon thereafter. If you see that as an exciting challenge, then you're on the right track. If not, then you may want to reconsider.

Really, the field is big enough that no amout of general tips can truly prepare you for it before you've experienced it. The one final thing I have to offer relates directly to Tip #3, though.

Programmer's Drinking Song:
(To be sung to the tune of 99 Bottles of beer on the Wall)

99 little bugs in the code,
99 little buuuuuugs.
Fix one then,
Compile it again,
101 little bugs in the code.

(Repeat until Bugs == 0)

littlequietguy
2009-10-28, 06:46 PM
Html is insanely easy at times. It fulfills a basic need.

Heliomance
2009-10-28, 07:52 PM
http://imgs.xkcd.com/comics/python.png

Miklus
2009-10-28, 08:25 PM
We use C and C++ at work. C is mainly legacy code, but we have to deal with it.

We don't really use the visual components. The general feeling here is that anything Mircosoft makes is crap and the senior programmers have made their own set of button and menus and such.

We don't really use the object orientated features either. They are deemed to be more trouble than they are worth. Virtual inheiritance and such is not used. This suits me just fine!

So it is visual object orientated programming without the visual and the obejcts...:smallsmile:

Good ol' functions! Those work!

Here are some pro tips:
1) Use meaningful variable and function names. Avoid variable names like "Data" and "x_pos".
2) Comment your goddamn code!
3) Put all the parameters in the function parameter list. No globals!
4) Avoid multithreading like the plauge. Two words: "Debugging" and "Forever".
5) no...goto :smallyuk:

If you can do these things you are already better than most programmers I have worked with, self-taught or otherwise.

Tirian
2009-10-28, 09:34 PM
are you trying to tell me to choose a different language to start with?

Oh, I'm not telling you anything. You can pick up C# as a first language if you have the dedication to do that. But it's a little like having a ten-speeder as your first bicycle; there are a lot of gadgets that you won't use at first and you'll fall down more often and more painfully than if you started with a one-speed bike with training wheels and graduated to your desired bike once you stopped falling down every five minutes. Even if you want to be a great cyclist, it'd be faster to get there if you start with a trainee bike that you will eventually outgrow, right?

It's sort of the same thing with programming languages. They're all different on the fringes, but they're all very similar in the core. A line like

if (temperature < 32) print("It's freezing!\n")
exists in 90% of all programming languages, although everyone has slightly different punctuation and rules for defining and using variables, everyone knows what this means. The first month or two of your programming journey is going to be learning about this paradigm of structured programming and how you can use loops and conditionals to achieve simple goals. It is the opinion of many that you may as well do that in a language with "training wheels" that has a clean, helpful interface and a lot of websites teaching you how to start. I think that Python is better at achieving that goal than C#. And by the time you've grown enough to take advantage of C#'s strengths, you won't have lost any time even though you'll have learned the fundamentals of a different language.

Don't think of programming languages as something that you have to be faithful to, like a baseball team or a car company. It's a tool for solving problems, and like carpentry you should know how to use lots of different tools properly and know when to use a screwdriver instead of a hammer and how to not try to use a screwdriver to hammer screws into a wall.

Jack Squat
2009-10-28, 09:41 PM
2) Comment your goddamn code!

The corollary to this is don't over comment. Telling what something does is good, but some things people should be able to look at and know what's happening (for instance, we probably know that node *left in a struct called BinaryTree is probably the left node of it, you don't need to tell us this. But do say what the binary tree is going to be used for).


5) no...goto :smallyuk:

http://imgs.xkcd.com/comics/goto.png


Yes, that will actually happen. I"ll make sure of it.
:smallwink:

Dr Bwaa
2009-10-28, 09:43 PM
I feel it necessary to put in my 2 cents (because I'm on the intertubes, and that's what people here do!):

DrScheme! (http://download.plt-scheme.org/drscheme/)
Scheme is a dialect of Lisp; it's really easy to use and functional programming is, frankly, cool. Though without decent guidance it may be a little hard to learn :p

Besides Scheme, I'd definitely recommend Java or Python, but any of the C languages would work, too. They're a lot like Java, but you can get into more trouble and they can be harder to debug (If you go with straight C, definitely get Valgrind for debugging) since they are lower-level and handle memory much more closely. For a beginner I would definitely recommend Python or Java before anything else; they're quick to learn and the basics carry over very well into other languages.

Decoy Lockbox
2009-10-28, 10:40 PM
Senior year computer science undergrad here, thought I'd chime in.



3) You will come to know the depths of true frustration in the course of your learning, and you may come to the mistaken conclusion that your compiler hates you. When this happens you should take a deep breath, remind yourself that the computer is a machine and therefore isn't a spiteful **** at all, and restrain yourself from putting your fist through your monitor. That's not where the brain of the computer is anyway.

Funny story about programming frustration. Last semester, my roommate stayed up for 64 consecutive hours working on a program for CMSC 473 natural language processing, i.e. "teaching your computer english". He failed the class. I managed to complete my code with only a single 48-hour session, and passed. To this day, I feel really bad for that guy.





6) For those languages that have {} to note compound statements, there are two ways of positioning them.

The unwashed heathen way:

if (you == unprofessional){
....cout << "This is how you write code.";
}

And the One True Way:

if (you == suaveAndAwesome)
{
....cout << "This is how you write code.";
}

Alright, technically both ways are correct, and this is something of a holy war among programmers that might make some people here a bit ticked, but I've shown you the light early on to make sure you aren't seduced to the dark side. :smalltongue:


I hate when people write in the "unwashed" way; the one and true way is so much more pleasing to the eye.

Dr Bwaa
2009-10-29, 03:19 AM
Funny story about programming frustration. Last semester, my roommate stayed up for 64 consecutive hours working on a program for CMSC 473 natural language processing, i.e. "teaching your computer english". He failed the class. I managed to complete my code with only a single 48-hour session, and passed. To this day, I feel really bad for that guy.

Ouch. I feel that.


I hate when people write in the "unwashed" way; the one and true way is so much more pleasing to the eye.

Undeniable fact. Listen to this man.

Decoy Lockbox
2009-10-29, 11:30 AM
Ouch. I feel that.

I once tried to explain programming to a liberal arts friend. I told her that it was like writing an very long essay. But unlike an essay, if you get your logic wrong in any part of the program, it could very well foul up the whole thing, not just a single argument. And if you forget a semicolon, it explodes.

Last semester, I had the dubious pleasure of teaching a programming-illiterate freshman how to program in C (they make math majors take "programming I for majors" at my college for some reason). You really forget how agonizing even the basics are once you get far enough into it. I could almost see the steam coming out of her ears when I tried to explain 2-D arrays to her.

Delwugor
2009-10-29, 01:36 PM
Don't worry about what language you use. VS C# Express is free and fairly easy to use go for it.

Programming is not a skill of using one language over another - it is a skill of taking ideas, figuring out the logic to do them and then finally programming that logic.
If you enjoy and/or are good at logic and logical thinking then you will probably end up liking programming.

I would recommend first going through one or two tutorials. There are many links to different tutorials here (http://www.programmingtutorials.com/csharp.aspx) or here (http://www.c-sharpcorner.com/Articles/ArticleListing.aspx?SectionID=1&SubSectionID=168) and one for VS C# Express (http://www.functionx.com/csharp/Lesson01.htm). Also go through a tutorial on windows forms, you want to be able to see your programming results, here (http://www.c-sharpcorner.com/UploadFile/jmukharjee/WindowsFormsTutorial111282005011245AM/WindowsFormsTutorial1.aspx) is one that you could look at.

These will help you with learning the basics but not really programming. To move forward with programming you want to program something that you can use.

Pick something small and easy you would like to do and can use. For example a random dice roller with a interactive screen and to display the dice roll.
Design a form (or maybe several forms) that you like. V in VS means visual and it is easy to quickly design a form.
Put together the logic of how you want to a random dice roller. You will want it to handle all the different dice types and rolling multiple dice as well, 2d6 1d20 5d8 ...
Program the logic - separately from the form. Keeping it separate is very important as you'll see.
Match up your form and what is entered in the form by the user (you) to the dice roller you just developed.
Run and watch your ideas give an answer to you. You want to see your results to appreciate your work fully.

If you liked what you did with your first idea then expand on that. For example as a DM you want to run combat on your laptop - well then program it.
Again design your forms for it (this will require multiple forms).
Put together the logic for handling things like stats for monsters, NPCs, PCs, Initiative order, combat sequence ... and finally rolling NPC attacks and damage.
Program those logical pieces. Remember programming the dice roller separately? You can use it again for rolling attacks and damage.
Match up all of the pieces into the forms and there you go again. Now you get to see your programming make your DMing job easier.

Now take all of those pieces you just did and instead of using a form put them together as a web pages. Your logic stays the same just the visual parts and how they interact with the logic change.

Outside of VS Express the most useful tool you can use is an Office product such as MS Office with Visio or the free Open Office with Draw. Why? To help organize and communicate (even to yourself) the logic of what you are programming and match it up to your interface.
Visio (or Draw) is a great tool to use in laying out the logic of what you are trying to do, and modifying the logic easily. So when you are deep into programming and the syntax of C# you can just look at your logic diagrams to keep it all together logically.

valadil
2009-10-29, 01:48 PM
I hate when people write in the "unwashed" way; the one and true way is so much more pleasing to the eye.

Care to explain why? I'm more familiar with the so called unwashed method but am happy to switch if I'm editing a file that's already formatted one way or the other. I ask because I don't have an opinion on the matter and good programmers are supposed to be highly opinionated and hostile about it.

OP, I haven't attempted C# so I can't give specific advice or suggest any tutorials. I will chime in to agree that python is an easier first language.

First of all you're less likely to get hung up on the syntax. Hunting down a missing semicolon or a mismatched parenthese is hell when you're not used to looking at code.

Python forms good habits for whitespace use by making whitespace mandatory. How you tab and indent your code helps make it more readable. This is crucial when you send your code to someone else or if you reopen a file 6 months after you first wrote it.

Python lets you get to the basics with a minimum of unintelligible code. I never liked Java as a first language because you have to create an object just to start. You're not ready at that point to grok what an object is so you just have to ignore those lines of code and hope that they magically work. Python lets you skip all that and just play with variables and textual output.

pendell
2009-10-29, 01:55 PM
Care to explain why? I'm more familiar with the so called unwashed method but am happy to switch if I'm editing a file that's already formatted one way or the other. I ask because I don't have an opinion on the matter and good programmers are supposed to be highly opinionated and hostile about it.


Personal preference; it's more a joke than anything. I've worked in shops that did it both ways, and I personally don't care. Use it either way, so long as it's done consistently within the same shop.

Respectfully,

Brian Pendell

Jack Squat
2009-10-29, 01:59 PM
Care to explain why? I'm more familiar with the so called unwashed method but am happy to switch if I'm editing a file that's already formatted one way or the other. I ask because I don't have an opinion on the matter and good programmers are supposed to be highly opinionated and hostile about it.

It looks prettier and is easier to read (meaning tell where the statement/function starts/stops). This makes debugging and editing easier.

The really annoying way is where you don't do between brackets returns at all, such as

if (you == Newbie){
....cout << "This is how you write code.";}

or

if (you ==TooLazyToHitEnter) { cout << "This is how you write code.";}

EDIT: Also what Pendell said. It doesn't matter if everyone does it the same way. The problem is that unless a workspace sets a standard, you're going to be jumping around between formattings which makes editing more of a pain than it already is.

Tirian
2009-10-29, 02:07 PM
Care to explain why? I'm more familiar with the so called unwashed method but am happy to switch if I'm editing a file that's already formatted one way or the other. I ask because I don't have an opinion on the matter and good programmers are supposed to be highly opinionated and hostile about it.

These people own stock in printer paper companies, so they want to be sure that your code contains absurd amounts of whitespace. :smallwink:

I will agree that one should learn to program with the thought that someone other than the compiler will be reading it someday. (Even if that person turns out to be you five years in the future, you owe it to yourself to not make it hard on you.) Choose good variable names, keep your line lengths to 80 characters where possible, and comment liberally but not ubiquitously. But if you're going to get ranty about this or how many spaces people use in their tab-stops, you need to get a grip.

CreganTur
2009-10-29, 02:09 PM
The best programming book I have ever read is Head First C# from Head First Labs. It's funny, engaging, full of plenty of projects and coding examples to work through... it's by far the best programming book I've ever read... and I've read a bunch!

Tirian
2009-10-29, 02:33 PM
The really annoying way is where you don't do between brackets returns at all, such as

if (you == Newbie){
....cout << "This is how you write code.";}

or

if (you ==TooLazyToHitEnter) { cout << "This is how you write code.";}


Okay, I'll admit that the Newbie example is a trainwreck, but JadeTarem's original "unprofessional" example of having the open quote with the conditional is perfectly readable. The close brace balances with the "if" or "while" or whatever. Get over it.

And TooLazyToHitEnter is also very sensible if you're doing something atomic and very understandable that all fits on one line. One of the lines that really sells Perl (and is legal but non-standard in most any modern language) is

open (FILE, "foo.txt") or die "I can't open foo.txt!"

I'd argue here that readability here would actually be harmed by pulling the consequent away from the conditional and throwing two extra lines of just braces in them.

Jack Squat
2009-10-29, 02:51 PM
Okay, I'll admit that the Newbie example is a trainwreck, but JadeTarem's original "unprofessional" example of having the open quote with the conditional is perfectly readable. The close brace balances with the "if" or "while" or whatever. Get over it.

His "unprofessional" one is a little less clean looking IMO, but I did use it for the longest time. Personally, I find it easier to find the where the brackets begin and end if they have their own lines, especially when nesting. Of course, keeping good indenting is more important. I think he posted his examples as a half-joke.

Like I said, I don't really care which method is used so long as it's consistent. It starts to get annoying when you're jumping through the different ones seemingly at random.


And TooLazyToHitEnter is also very sensible if you're doing something atomic and very understandable that all fits on one line. One of the lines that really sells Perl (and is legal but non-standard in most any modern language) is

open (FILE, "foo.txt") or die "I can't open foo.txt!"

I'd argue here that readability here would actually be harmed by pulling the consequent away from the conditional and throwing two extra lines of just braces in them.

If you've got one statement, you don't even need to use brackets, but I find the people who vary up their formatting tend to get more bugs, at least when starting out (I was one of them for awhile - I'd go back in, add another line and forget to add brackets in). If you have more than one command, you need to have multiple lines anyways. My dislike of that one is more of one with consistency than thinking it actually looks hideous.

Delwugor
2009-10-29, 03:01 PM
Reading code from a TooLazyToHitEnter programmer is not a problem in the world of modern IDE's. All I have to do is remember Ctrl+E,D bingo done and then I concentrate on more important things.

Pyrian
2009-10-29, 03:22 PM
Of course, keeping good indenting is more important.Seriously. The indent is consistent across almost all programming languages and styles.

Jack Squat
2009-10-29, 03:43 PM
Seriously. The indent is consistent across almost all programming languages and styles.

I'm generally referring to people not correctly indenting. The editor used in my classes (vim) would auto-indent for you. And if by some means you managed to screw it up (normally by deleting lines and moving stuff around), all you have to do is run the command to straighten it up (number of lines, '=='). Not that big of a deal when if you're editing a pre-written file, but it's a different story in a class setting when someone would need help with something and their code resembles something similar to buckshot spray.

Jade_Tarem
2009-10-29, 03:44 PM
Okay, I'll admit that the Newbie example is a trainwreck, but JadeTarem's original "unprofessional" example of having the open quote with the conditional is perfectly readable. The close brace balances with the "if" or "while" or whatever. Get over it.

And TooLazyToHitEnter is also very sensible if you're doing something atomic and very understandable that all fits on one line. One of the lines that really sells Perl (and is legal but non-standard in most any modern language) is

open (FILE, "foo.txt") or die "I can't open foo.txt!"

I'd argue here that readability here would actually be harmed by pulling the consequent away from the conditional and throwing two extra lines of just braces in them.

If I was seriously that bent out of shape over it, I would have used much less melodramatic and goofy terms than the "One True Way," and I wouldn't have acknowledged that both ways are correct. It is, however, the way I was taught, according to the logic of "Yes, there's more whitespace, but at least it's always 100% clear where compound statements begin and end.

What's more, all of your {} will line up, which means that you can use your indentation to help you look for missing braces if you mess up. If your braces are hiding in lines that have code all over them, you're on your own.

And seriously, while I appreciate the "save the trees" mentality, I haven't printed out my code on actual paper in a long time.

BugFix
2009-10-29, 09:51 PM
The unwashed heathen way:

if (you == unprofessional){
....cout << "This is how you write code.";
}

And the One True Way:

if (you == suaveAndAwesome)
{
....cout << "This is how you write code.";
}

Alright, technically both ways are correct, and this is something of a
holy war among programmers that might make some people here a bit
ticked [...]

No offense, but one of the easiest ways to mark yourself a member of the unwashed heathen masses is to let on that you think "programming style" is an purely issue of where you put the whitespace. Seriously, don't do this in a job interview. And if the folks conducting the interview do it, run.

Languages have syntax. Programmers and tools have styles. You're expected to know the former, regardless of style and conform to the latter where needed. Real style is about meaning and clarity, not formatting. As long as your whitespace isn't being used (e.g. bad indentation) to deliberately lie to your reader, you're fine. Write code to match what you're modifying, and deal with what came before without whining.

Tirian
2009-10-29, 11:01 PM
And seriously, while I appreciate the "save the trees" mentality, I haven't printed out my code on actual paper in a long time.

No, I haven't either. But I used to, and that practical reality contributed to my personal revelation of what is unreadable. I'm not going to say that it's right or wrong, but it's no more right or wrong than the opinions that anyone else formed in good faith.

I will say that I still follow the rule that a subroutine (minus the leading comments) should fit on "a screen" (both by length and width) when possible, with the understanding that I might not know the viewing habits of the next person to view my code. Based on that, whitespace is like comments; too little is bad but too much isn't much better. More relevantly, it leads me to think about chunking out a new subroutine if I'm doing something intense inside three levels of indentation. I won't say "always do that", but if what you're doing in there can be described in two or three words, then that's often a good name for a subroutine even if it is only called once.

Finally, I didn't mean my words as a personal attack against you. When I said that people who elevate whitespace debates to Holy Wars should get over themselves, I was pretty certain that your intensity was farcical. Still, I will echo what BugFix just said well; a quick route to being unprofessional (in the form of not being hired onto a team) is giving the impression that you can only write code "your way" and you can't read anyone's code that doesn't conform to your standards. Find your own standard but be prepared to work with other good-faith standards and you will have a valuable programming skill indeed.

Jade_Tarem
2009-10-29, 11:34 PM
This is getting a bit ridiculous. :smallannoyed:


No offense, but one of the easiest ways to mark yourself a member of the unwashed heathen masses is to let on that you think "programming style" is an purely issue of where you put the whitespace.

Yes, because that's exactly what I posted. Really. I can look back and see my post right now, the part where I said "Programming style is all about where you put the whitespace! There's nothing more important in the whole world."

Oh wait, no I can't, because I never said anything like that. I made a crack about a preference for where curly braces go when indicating where compound statements begin and end. I indicated at the time that a bunch of other people thought differently, and also indicated (unsuccessfully, it seems) that taking it too seriously was probably a bad idea, using terms such as the One True Way and the Dark Side, which we all know are phrases I drop at job interviews whenever possible.

Sweet bit-flipping zombies! It was a cheap joke I inserted into a list of general advice, for the benefit of other programmers to grin at. Next you'll be telling me that the drinking song I submitted is bogus because it doesn't really match the syllable counts in 99 Bottles of Beer on the Wall.

So let me be dead serious here. You are absolutely correct. Everyone codes differently, and as long as it's readable, then it's a valid way of doing things. For the past three months, I've worked just fine in two classes with a partner who codes religiously in the "unwashed heathen" way, and I've had no problem with it. I certainly haven't started trying to "convert" him, nor do I make Darth Vader's respirator noises whenever he walks in the room.

I hope that clears things up.

Pyrian
2009-10-29, 11:47 PM
I'm generally referring to people not correctly indenting.I meant that as an agreement. Indenting properly is important to me precisely because I have to program in many different languages and indentation use is generally consistent across them. When I'm looking at structure, I'm not paying much attention to things like braces, so if it's not indented properly I might miss it.

...I can't imagine having to go over schoolkids code. :smalleek: The professional work I'm frequently called on to edit is bad enough.

HandofCrom
2009-10-30, 01:17 AM
I might sound like a bit of an jerk for saying this, but while python or Java may be a place to start playing with programming, if you are serious, you might as well start with assembly. My assembly class was the most influential class on programming for me. It gives you a deep understanding of how the computer works and it forces you to use a rigor and attention to detail that is vital for programming. After that, C# is also good. It is a lot like Java, though I think the GUI aspects are much better supported, so if you want to create simple apps, it is a good place to start.

For assembly, start at
http://www.masm32.com/
and its forums.

For C#, start at
http://msdn.microsoft.com

These are if you want to do apps and deeper programming. If you are more interested in webdev, look into html and css to start, and then look into a scripting language like python, javascript, or asp.net.

Understand, programming is not a simple skill. It takes a lot of work and discipline, and their is much to learn. Decide what you want from it, and go pedal to the metal for it.

edit: cleaned up my language

Decoy Lockbox
2009-10-30, 01:23 AM
If I was seriously that bent out of shape over it, I would have used much less melodramatic and goofy terms than the "One True Way," and I wouldn't have acknowledged that both ways are correct. It is, however, the way I was taught, according to the logic of "Yes, there's more whitespace, but at least it's always 100% clear where compound statements begin and end.

Aw man, given your zealot avatar, I figured we were one guy away from girding ourselves in steel for the oncoming holy war. The heretic indenters will be purged from this land!

Jade_Tarem
2009-10-30, 01:28 AM
Aw man, given your zealot avatar, I figured we were one guy away from girding ourselves in steel for the oncoming holy war. The heretic indenters will be purged from this land!

I have 5 Engineering classes right now and finals are coming up. I don't have time for a cyberspace Jihad. :smalltongue: