Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 [2] 3 4 5

Author Topic: Learning Programming  (Read 4035 times)

Tyius

  • Bay Watcher
    • View Profile
Re: Learning Programming
« Reply #15 on: June 13, 2011, 03:38:28 pm »

C++ is a great language, it's just a lot easier to mess up in...  Thus why it wouldn't be great for a beginner lol.  Also, I am a computer science major lol so learning from me isn't too bad of an idea, (so are 90% of the people with youtube tutorials though) programming is almost entirely about having good style.  Keep your code organized in some fashion and it wont be too bad of a start.  Plus man a lot of people here are probably fairly competent at programming, seriously though it's a good idea to start out with something a bit simpler than C++ and to work your way into it once you have good fundamentals built up from some other C syntax language.  On a side not it might be cool to pick up a programming book from somewhere and just use that to get yourself a nice grounding in a language of your choice (please something other than python lol).
Logged
The murders are for their own good. I regret none of them. All were sound decisions made to balance the scales in favor of prosperity.

ILikePie

  • Bay Watcher
  • Call me Ron
    • View Profile
Re: Learning Programming
« Reply #16 on: June 13, 2011, 03:43:32 pm »

Here's just one example: The const keyword.
That's just C's insane declarations, I've seen whole chapters in books devoted to them. C is wonderful by the way, but not very beginner friendly. My first C programs used to always end in a segfault.
Logged

olemars

  • Bay Watcher
    • View Profile
Re: Learning Programming
« Reply #17 on: June 13, 2011, 04:48:01 pm »

First off: Why are you even asking us? This is a gaming forum. Ask this in a programming forum like CodeCall, or better yet ask a real programmer or CS professor. You're most likely going to hurt yourself learning from fools like us, and honestly I don't want to see that happen.


C++, I've been told by a number of sources, is a messy and unsafe language. Stay away from it, at least for now.

My suggestions: If you absolutely want to learn a C-like language (I'm lumping in Java, C-Sharp and Python into this) either get into Python, which is apparently quite beginner-friendly, or learn straight C. this will help you in the long run.

But here's the thing: if you want to get closer to the mathematical side of programming, and what the stuff actually is, start off with things like lambda calculus, Scheme, Haskell and Lisp. These languages will be much easier to swallow with a background in lambda calculus (trivial to learn the basics in; ask soundandfury in NewNet #bay12games for the basics and the textbooks, or ask LNCP) or just mathematics in general, and will probably benefit you as a blank slate. These are good to know.

tl;dr : If you want to be a lazy bum and just learn how to write things, go w/ C or Python. Probably Python first, then C. But if you want to learn a bit more, get to know the topic, learn those along with Lambda Calculus and either Scheme or Haskell.

There are a few programmers here you know, some of us even do it for a living...

Telling someone to start with C when learning programming is extremely bad advice. At this point C is a legacy language, and learning it with a goal of progressing to C++ will just lead to frustration and picking up lots of bad habits (since the differences between C and C++ can be subtle yet critical). C++ also get a lot more hate than it deserves. People only run into trouble when they try to get too fancy with it.

Beyond that I believe it doesn't really matter what language one decides to start with. Hell, my starting point was FORTRAN. The important step is finding a learning form that keeps the interest up, like a solid set of tutorials and guides. Python can be good there.
Logged

alfie275

  • Bay Watcher
    • View Profile
Re: Learning Programming
« Reply #18 on: June 13, 2011, 04:57:22 pm »

Perhaps (dare I say it?) Byond? It's pretty simple, and to an extent OOP.
Logged
I do LP of videogames!
See here:
http://www.youtube.com/user/MrAlfie275

olemars

  • Bay Watcher
    • View Profile
Re: Learning Programming
« Reply #19 on: June 13, 2011, 04:58:39 pm »

Yes, but all Byond programmers seem to become douches after a month or two. It's like there's a taint.
Logged

lordnincompoop

  • Bay Watcher
  • Allusionist
    • View Profile
Re: Learning Programming
« Reply #20 on: June 13, 2011, 05:03:18 pm »

There are a few programmers here you know, some of us even do it for a living...

I was actually rather surprised at the programmer demographic here. But!

That does not make up for the fact that this is not a programming-oriented forum, nor are a lot of us experts in that subject anyway. He'd benefit more from seeing, say, a forums dedicated to that stuff where many more programmers and CS folks would hang out.

Telling someone to start with C when learning programming is extremely bad advice. At this point C is a legacy language, and learning it with a goal of progressing to C++ will just lead to frustration and picking up lots of bad habits (since the differences between C and C++ can be subtle yet critical). C++ also get a lot more hate than it deserves. People only run into trouble when they try to get too fancy with it.

Just goes to show what I know. :P
Logged

Dwarf

  • Bay Watcher
  • The Light shall take us
    • View Profile
Re: Learning Programming
« Reply #21 on: June 14, 2011, 03:08:46 am »

Haskell? Lisp? Scheme?
Those languages are used fairly sparingly.
If you're learning them for fun, it's ok I guess, but knowledge in these languages is not going to be very useful.

I'd say it's much more important what you actually want to do.
There's not one language (Well, there used to be - C - but we moved away from that).
If you want to program games and such, learning Python and getting acquainted with PyGame or something might be a good idea. Java would be another choice there.
If you want to look at the more fundamental aspects of computers, you'd probably want to have a look at C or C++, but as mentioned before, it's not really a beginner's choice, though C is/was my first language - then again, I'm not a pro by a long stretch :P

If you're a science kind of guy, Fortran might also be worth to take a look at. It's getting a bit exotic by now, but it's fairly easy, simple, and, most of all, fast (number crunching). However, it seems to slowly lose ground to C/C++.

If you're keen on easy development for Windows, C#, Visual Basic and the whole .NET thingamajig is usually a good choice. Be aware however that you're locking yourself on Windows, which is not A Good Thing. It's UNIX that makes the world move.
« Last Edit: June 14, 2011, 03:12:29 am by Dwarf »
Logged
Quote from: Akura
Now, if we could only mod Giant War Eagles to carry crossbows, we could do strafing runs on the elves who sold the eagles to us in the first place.

lordnincompoop

  • Bay Watcher
  • Allusionist
    • View Profile
Re: Learning Programming
« Reply #22 on: June 14, 2011, 04:48:45 am »

Yes, interest in functional programming and combinatory logic is mainly academic, which is why I suggested it in the first place. It's interesting stuff, and as it's closer to the mathematical origins of programming he might be interested in that.

"Programming" is an incredibly broad topic. I suggested this because I'm assuming he's learning out of interest in the field and, say, the languages.
Logged

Gamerlord

  • Bay Watcher
  • Novice GM
    • View Profile
Re: Learning Programming
« Reply #23 on: June 14, 2011, 04:53:56 am »

Last year at school we were shown some really basic programming with Karel the Robot. It was enjoyable and easy to learn. It really teaches you not to make any errors or it won't work.  :P

Azzuro

  • Bay Watcher
    • View Profile
Re: Learning Programming
« Reply #24 on: June 14, 2011, 05:45:34 am »

Actually, it's probably reading the \t as a tab character. Use \\t and it should be fine. Note how the \ after C: was doubled in the error message? I guess \P isn't a recognised escape sequence, or it specially handles C:\.

Edit: to clarify, talking about
Quote
Code: [Select]
Traceback (most recent call last):
  File "C:/PythonFiles/textreader", line 1, in <module>
    text = open("C:\PythonFiles\testtextfile.txt", 'r')
IOError: [Errno 22] invalid mode ('r') or filename: 'C:\\PythonFiles\testtextfile.txt'

The \\ is  a strong indicator that python uses escape sequences starting with \, and the single \ followed by a t is a fairly good indication that it is reading that as "C:\PythonFiles<tab>esttextfile.txt". Try rewriting it as "C:\\PythonFiles\\testtextfile.txt".

Note the table in http://docs.python.org/reference/lexical_analysis.html#string-literals

Thanks, this was the cause of the error.

Also, I'm doing C++ on the side, and I'm having trouble with the "while" loop. I wrote a simple calculator program with three files.

Spoiler (click to show/hide)

The while loop in main.cpp doesn't work. I had intended to make to calculator keep asking for another calculation until the user quit, but the program just does it once and exits anyway. Do I need to use goto: or break?
Logged

United Forenia Forever!

olemars

  • Bay Watcher
    • View Profile
Re: Learning Programming
« Reply #25 on: June 14, 2011, 06:39:06 am »

You have a rogue semicolon in your last else if. Compilers usually warn about it, but since it's not technically an error it passes through.

Oh, and never use goto. Ever.
Logged

Azzuro

  • Bay Watcher
    • View Profile
Re: Learning Programming
« Reply #26 on: June 14, 2011, 06:44:26 am »

Okay, the loop executes fine now. But why exactly does that semicolon cause the error?

Also, what's wrong with goto?
Logged

United Forenia Forever!

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: Learning Programming
« Reply #27 on: June 14, 2011, 07:04:08 am »

Just, please, don't do it, please. For your own sake.

goto makes code messy, very messy. Impossible to maintain messy. Just thinking about it is a sin! Break statements are also avoided when possible.

olemars

  • Bay Watcher
    • View Profile
Re: Learning Programming
« Reply #28 on: June 14, 2011, 07:08:58 am »

Semicolons in C++ terminates a statement. Think of it as a carriage-return of sorts. With the semicolon in place the else if executes an empty statement (the empty "space" between the parenthesis and the semicolon), and then the loop = 0 as a separate statement. Thus loop = 0 is executed on every iteration of the while loop.

The below is also valid code and might illustrate it for you better (your formatting is good and proper though):
Code: [Select]
while (loop == 1)
    {
        choice = option();
        if (choice == 1) add();
        else if (choice == 2) sub();
        else if (choice == 3) mul();
        else if (choice == 4) div();
        else if (choice == 5) ;
        loop = 0;
    }

Another consequence of this is that double semicolons ;; is also valid (but meaningless) code.

Goto ruins the flow of the code and really shouldn't have been included in the language. It's a remnant from the punch-card days. Break and continue is OK, but should be limited (they're useful in certain long loops). Break is mainly used in switch blocks.
Logged

zeet

  • Bay Watcher
  • Programming lunatic.
    • View Profile
Re: Learning Programming
« Reply #29 on: June 14, 2011, 08:31:58 am »

Using gotos can lead to some very bad code, also xkcd explains pretty well why not to use goto:
http://xkcd.com/292/
Logged
Pages: 1 [2] 3 4 5