Bay 12 Games Forum

Please login or register.

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

Author Topic: Learning Programming  (Read 4034 times)

Azzuro

  • Bay Watcher
    • View Profile
Learning Programming
« on: June 13, 2011, 07:54:57 am »

In an effort to not waste my childhood away and then look back on it and sigh when I'm older, I have decided to learn computer programming. Any help from you guys on here would be much appreciated.

I know absolutely nothing about programming, beyond how to install games and other programs on my computer, etc.

Based on various recommendations, I'm using Python 2.7.1 and learning off this set of tutorials. If any of you could recommend more tutorials or lessons, I would appreciate it.
Logged

United Forenia Forever!

Max White

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

I know absolutely nothing about programming, beyond how to install games and other programs on my computer, etc.

Based off the fact that you see installing a game as programming, I would say you do not know what programming is at all. Don't worry, not many do. In a technical sense, programming doesn't even revolve around a computer, we just use them as our tools of choice because they are great at handling logical rules.

I would recommend c# or even visual basic over python for newbies. Learn to program in a strongly typed language, it will pay off.

Azzuro

  • Bay Watcher
    • View Profile
Re: Learning Programming
« Reply #2 on: June 13, 2011, 08:31:52 am »

I would recommend c# or even visual basic over python for newbies.

Is c# or visual basic easier? I tried to learn C++ about a year or so ago, and I didn't know anything and quit. I'm using Python now because it seems a lot easier.

Also, I have a question to ask:

Code: [Select]
text = open("C:\PythonFiles\testtextfile.txt", 'r')
text.read()

This bit of code refuses to run, for some reason. It gives me an error:

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 file and the text file it's reading from are in the same directory, but I don't know whether the path to the text file should be put in or not.
Logged

United Forenia Forever!

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Learning Programming
« Reply #3 on: June 13, 2011, 08:35:41 am »

Tried it without the path yet?


Besides that, your interpreter may also be expecting a different kind of slash, depending on if it's originally a unix interpreter or not.
Logged

zeet

  • Bay Watcher
  • Programming lunatic.
    • View Profile
Re: Learning Programming
« Reply #4 on: June 13, 2011, 08:48:26 am »

Use:
open('C:/PythonFiles/testtextfile.txt', 'r')
Instead.
Or simply:
open('testtextfile.txt', 'r') if the file is in same directory as python sourcefile.
« Last Edit: June 13, 2011, 08:51:52 am by zeet »
Logged

Glowcat

  • Bay Watcher
    • View Profile
Re: Learning Programming
« Reply #5 on: June 13, 2011, 08:53:33 am »

You don't necessarily have to learn programming alongside a language.

Many preparation courses first teach using pseudocode to focus on ideas such as variables, loops, memory allocation, arrays, functions, etc. Then you adapt your knowledge to the particular language you want to use.
Logged
Totally a weretrain. Very much trains!
I'm going to steamroll this house.

Azzuro

  • Bay Watcher
    • View Profile
Re: Learning Programming
« Reply #6 on: June 13, 2011, 08:55:53 am »

Trying it without the path works, but I'd like to know how to read from file that aren't in the same directory.

Also:
Code: [Select]
text = open("testtextfile.txt", 'r')
text.read()
text.seek(0, 0)
print text.read()

That's the code now. How come "print text" doesn't work, but "print text.read()" will? I was under the impression that the contents of the text file was a string under "text".
Logged

United Forenia Forever!

Darvi

  • Bay Watcher
  • <Cript> Darvi is my wifi.
    • View Profile
Re: Learning Programming
« Reply #7 on: June 13, 2011, 08:57:34 am »

Because text is a document and you cannot actually print a document. Only its contents. Or something.
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Learning Programming
« Reply #8 on: June 13, 2011, 09:02:42 am »

Trying it without the path works, but I'd like to know how to read from file that aren't in the same directory.

Also:
Code: [Select]
text = open("testtextfile.txt", 'r')
text.read()
text.seek(0, 0)
print text.read()

That's the code now. How come "print text" doesn't work, but "print text.read()" will? I was under the impression that the contents of the text file was a string under "text".
text is probably a file object or something and python doesn't have a standard method for printing file objects. text.read() is a function that returns the contents of text as a string, which is an object type that python knows how to print.
Logged

qwertyuiopas

  • Bay Watcher
  • Photoshop is for elves who cannot use MSPaint.
    • View Profile
    • uristqwerty.ca, my current (barren) site.
Re: Learning Programming
« Reply #9 on: June 13, 2011, 11:08:20 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
« Last Edit: June 13, 2011, 02:55:04 pm by qwertyuiopas »
Logged
Eh?
Eh!

Tyius

  • Bay Watcher
    • View Profile
Re: Learning Programming
« Reply #10 on: June 13, 2011, 02:30:11 pm »

C++ is incredibly hard to learn when you are younger, especially if you have no prior programming experience.  I'm not so sure about python as a first language either...  Somebody already suggested one of the BASIC languages, and that might be a good place to start.  If you want to learn a more C syntax language off the bat and get into C++ later then C# and Java are both pretty solid choices.  My advice no matter what language you decide on is to find some good tutorials on youtube and follow those, and every now and again challenge yourself with a small project that incorporates the things you have learned.  If you decide on Java I would be more than willing to help you out, if you choose C# i might be interested in learning that along with you, and if you stick with python I wish you the best of luck.
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 #11 on: June 13, 2011, 02:39:55 pm »

C# is awesome if you use Windows. A bit less on OS X and Linux, but still a great starting point.
Logged

lordnincompoop

  • Bay Watcher
  • Allusionist
    • View Profile
Re: Learning Programming
« Reply #12 on: June 13, 2011, 02:54:07 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.
Logged

alfie275

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

If it's worth anything, I learnt Game Maker first, the graphical bit, then moved on to C++.
C++ is not really bad in any sense, it just puts more responsibility on you.
Logged
I do LP of videogames!
See here:
http://www.youtube.com/user/MrAlfie275

lordnincompoop

  • Bay Watcher
  • Allusionist
    • View Profile
Re: Learning Programming
« Reply #14 on: June 13, 2011, 03:07:51 pm »

C++ is not really bad in any sense, it just puts more responsibility on you.

Honestly, I do think there are parts of the language that could need improvement.

Here's just one example: The const keyword.
Logged
Pages: [1] 2 3 ... 5