• Welcome to Smashboards, the world's largest Super Smash Brothers community! Over 250,000 Smash Bros. fans from around the world have come to discuss these great games in over 19 million posts!

    You are currently viewing our boards as a visitor. Click here to sign up right now and start on your path in the Smash community!

Learning Python?

Ravener

Smash Apprentice
Joined
Jan 9, 2009
Messages
144
Location
Western Australia
I have recently been interested in computers and have learnt that to become good at computing i will need to learn some programming.

So, I've been searching around for the most easiest and user friendly programming language to learn and i found out it was python!

Do you guys think a computer noob should start out with python or if not what programming language?
 

TheBuzzSaw

Young Link Extraordinaire
Moderator
BRoomer
Joined
Jul 21, 2005
Messages
10,478
Personally, I do not like Python and its funky syntax.

What kind of stuff do you want to do with your programming someday? Python is a scripting language more than an actual programming language.
 

Kirby King

Master Lameoid
Premium
BRoomer
Joined
Feb 8, 2002
Messages
7,577
Location
Being a good little conformist
FWIW here they have intro courses that teach Python, Java, and C. The C-based course is the primary introductory CS course here (so largely, but not at all exclusively, taken by people who are going to be continuing with CS). Java is taught in a course that's kind of a precursor to that but isn't required of anyone and I think focuses a bit more on "computer science" more generally. The Python course I think is a bit less intensive and meant more for people not planning to go into CS more.

So what all that should mean to you is really up to you, but it's not bad to know a scripting language and Python's a reasonable choice. I don't know it terribly well, but I've used it in a class I took in high school and recently when I needed to write a small bit of code that dealt with huge numbers (which Python handles natively). If you might be interested in something more "traditional," I'd recommend C.
 

Vyse

Faith, Hope, Love, Luck
BRoomer
Joined
Jul 6, 2005
Messages
9,561
Location
Brisbane, Australia
I'm learning Python right now.
Just finished an assignment making an English to German dictionary.

Like KK said, C is a good place to start.
 

AltF4

BRoomer
BRoomer
Joined
Dec 13, 2005
Messages
5,042
Location
2.412 – 2.462 GHz
C gives you a good understanding of exactly how computers in general work, too. Simply because it's a much lower level language.

(It will also be harder to learn for just this reason)
 

Big Sean

Smash Journeyman
Joined
Jun 3, 2003
Messages
484
Location
Berkeley
I'm going to say Python is a great decision for a programming language. But i'm also going to refer to TheBuzzSaw and say that it depends on what your doing. You will probably hear a lot people talk in the future about how python is not a "real" programming language. Or that it is basically cute, but not useful for real applications. You will also hear alot of people talk about python like its gods greatest gift to mankind. My opinion is more of the latter, although not entirely of course :)


If your just looking for the easiest programming language, then by far its python:

canonical c hello world:

#import <stdio.h>

int main(int argc, char * argv) {
printf("Hello World!");
return 0;
}

# $ gcc hello.c -o hello
# $ ./hello

canonical python hello world:

print 'Hello World!'

# in an interactive interpreter press enter
# in a file: $python filename.py

If your looking for a languages thats extremely powerful, then by far choose python:

The reason is is that if you want to learn about programming python incorporates ideas for many of the major philosophies of programming. Schools today teach about the benefits of object oriented programming, and most students can throw out reasons on the fly of why object oriented is better than procedural programming. But most schools also don't teach about functions as first class data types, list heavy programming, dynamic typing, closures, mutual recursion, lambda, or lazy interpretation. These are ideas that can fundamentally change the way you think about programming, and are also not present in any of the c style programming languages.

I would also say that if you are more interested in the nuts and bolts/ones and zeroes of the computer then pick up c AND x86 assembler. These languages force you to think in terms of how the computer will run code, rather than what you want your code to eventually accomplish. If you want to learn real object-oriented programming, my pick would be smalltalk :) Of course if you want to learn Object oriented programming the industry way I would say c# via mono ! My favorite object oriented programming besides smalltalk is definitely python. The stuff you can do with it is just really astounding.

Edit: Oh and Python is not a scripting language. It is a full featured programming language that can be used for scripting. Personally I think its a subpar scripting language for games, and I definetly prefer to use lua, or tcl, which are designed to be scripting languages, and do it well. A python interpreter is quite a bulky addition to a video game already written in another language.
 

Ravener

Smash Apprentice
Joined
Jan 9, 2009
Messages
144
Location
Western Australia
Ok thanks for all the replies and tips :)
But I'm still 50/50 on wether to use python or C (because i pretty much know the basics of python). However is python a scripting language or not? and I'm in high school atm and was looking to mayby get into software engineering in the future.
 

Big Sean

Smash Journeyman
Joined
Jun 3, 2003
Messages
484
Location
Berkeley
Wikipedia:
<quote>
General-purpose dynamic languages
See also: Dynamic programming language

Some languages, such as Perl, began as scripting languages but were developed into programming languages suitable for broader purposes. Other similar languages – frequently interpreted, memory-managed, or dynamic – have been described as "scripting languages" for these similarities, even if they are more commonly used for applications programming. They are usually not called "scripting languages" by their own users.
</quote>

Perl was designed as basically a language that would be just a helper in shell scripts. That is its primary purpose was to work with programs written in other languages and provide a glue to combine them in useful ways. This is not the case in python. Python was written to be able to do anything a "real" programming language can do, because it is one! As the article points out, some people think of it as a scripting language because it is a dynamic one. What is a dynamic language? Its a language that can decide on how it will run code on runtime. This means that in python you can write code like:

eval("print 'hello world'")

This piece of code actually takes a string of python code, and executes it immediately. This is actually quite cool because that means you can write python code, that can write python code, then execute it. This is a feature not present in any of these c style languages.

Thats pretty much the jist of it. For some reason, people think that if there's extra power in the language, then its just a toy and not really worth programming in. Really python is much better described as an applications programming language, along with java and c#. Although i feel its important to note that python can be used a very good systems programming language as well:

C compiler written in python:
http://people.cs.uchicago.edu/~varmaa/mini_c/

An operating system written in python:
http://code.google.com/p/cleese/

A scheme interpreter written in python:
http://www.xs4all.nl/~yduppen/site/psyche.html

A python interpreter written in python:
http://codespeak.net/pypy/dist/pypy/doc/
 

Kirby King

Master Lameoid
Premium
BRoomer
Joined
Feb 8, 2002
Messages
7,577
Location
Being a good little conformist
There's an important distinction between "can be [ab]used for" and "is well-suited for". I could write a webserver in PHP, but its performance will suck and it won't be terribly fun to write because PHP's not well-suited for implementing servers. You could make it do that if you really wanted (or had a sufficiently persuasive reason to, and accepted the performance tradeoff), but it's more an abuse of the language than anything else. So just because you could write an operating system or C compiler in Python isn't to say you necessarily should, or that Python is well-suited for those kinds of tasks.
 

Big Sean

Smash Journeyman
Joined
Jun 3, 2003
Messages
484
Location
Berkeley
Maybe I jumped the gun when i said is a very good systems programming language. And you are absolutely correct that python should really not be used to write an operating system. However I do feel totally justified in saying that python should really considered an applications language, because that is what it is well suited for. Lets say I want to write a gui. Super easy to write in python, and just as fast as any other language because gui's usually spend all their time waiting on user input. A 2d video game, either most of the time its waiting, or if its not it will certainly refresh at 60fps pretty easily. A 3d video game, because their will be very little python interpretation going on, and many more calls to opengl. One of my favorite applications is that Eve online wrote most of their server IO in python because of performance reasons not because of ease of programming! And of course we all know python can do web well.

The only place I see where python fails is in low level programming, and where extreme speed is needed. Everything else is done very well in python. The scripting ability is really just a plus. In reality if you wan't to be software engineer you should really learn both languages plus, way way more. But as a first programming language, python has all of the capabilities of most other languages plus more, in an amazing syntax. When you want to write your first operating system from scratch (note you'll need assembler), or do your first molecular dynamics simulation (note you'll want supercomputer access), then maybe it will be time to pick up a language closer to the hardware, but I have a feeling that day is far off. If you want to do pretty much anything else besides these things and a few others, programming in c is just making it way harder than it needs to, and should be.

Edit: I'll also add your "[ab]used"/"well suited" metaphor that to me, c is really not "well suited" for many of the things python is good for. Writing a simple calendar gui can be done in c relatively straightforwardly but it won't be terribly fun to write because c's not very well suited for writing guis. This is because c was designed to do one thing well, write the unix operating system. A lot of people think that because it can write an operating sytem well it should be good for everything, however this is far from the truth.
 

Ravener

Smash Apprentice
Joined
Jan 9, 2009
Messages
144
Location
Western Australia
Ok you guys completely lost me about half way through talking about something.
And could someone please list the advantages and disadvantages of both python & C, it would be greatly appreciated.
 

Big Sean

Smash Journeyman
Joined
Jun 3, 2003
Messages
484
Location
Berkeley
I feel scared to even do this, since the most beautiful parts of python and c are really quite advance. Lets see though . . .

c --
Advantages:

compiled -- this means that you write code that goes through a program called a compiler that converts your text into nearly exact instructions as your c code. This makes it very very fast.
Static Data typing -- This is very important for safety reasons. This means that in case you wanted to work with a function call add, and you by mistake pass it a sentence, the compiler will tell you before you even run the code.

Low level data types -- This is really what makes this language wonderful, and what allows it to be a low level language. When you ask the computer for space to store your integers or whatever, the size is optimized for that specific computer. So when you want to do math on a 32 bit processor you get a 32 bit integer, and your code becomes radically faster. If you want to point to an address in a 64 bit system, you get exactly 64 bits for that. The most amazing data type in c is the pointer. This is a variable that holds the address data type in memory. This is fairly advance, but i'll just add that this kind of power is absolutely necessary when writing an operating system. Its also absolutely necessary when working on lower level hardware. For instance if your coding firmware for the arm of a robot, you often have to directly write to an address to send a voltage to an external circuit.

ubiquity -- Almost every piece of hardware from the NERSC supercomputers to the headlight in your car has a c compiler written for it. You can feel safe that if anyone ever comes up to you with a sega game gear, that you can write code for it.

industry standard -- If you want a job there's a good chance that they might ask to see some of your c skills. And i'm not talking about this c++ like c99 c. I'm talking about old school K&R c so that you can patch up their ancient code.

Disadvantages --
Reliance on the stack -- Lets say you want to ask c for some data. Say one million 64 bit floating point numbers because your recording music or something.
So you say: double x[1000000], which means an array of 1 million numbers. How c asks the computer for this is by previously reserving a large chunk of memory called the stack, and then giving out memory from this reserved buffer. The problem is is that you just asked for memory larger than the buffer. This is called a stack overflow, and the solution leads to a whole other set of problems ...

Poor runtime memory allocation -- so if you want that kind of memory you have to allocate it from a part of the memory called the heap. The problem is that memory from here is not automatically destroyed when your done with it. I'm sure you've heard the term memory leak, well this is when someone writes a program that continually borrows memory from the heap, and never returns any. If someone claims that a program has a memory leak, you can be sure that it was written in either c or c++.

pointers -- although I did state that pointers where totally amazing, they are also ridiculously dangerous. From a practical perspective they are hella annoying because often times subtle bugs will pop up that involve you pointing to an address that doesn't exist. This happens really frequently and results in errors like the infamous SIGSEGV or segmentation fault, that can make a grown man cry. More scary than this however is the tactic to use pointers in a malicious way. Hackers can often change the values of pointers to point to code of their own writing, which pretty much means that at the point they can have complete control over your computer. This is called a buffer-overflow hack and is the world's most popular hack. More specifically the windows kernel was known to have tons these security holes, i have no idea if they have been fixed. One of the major design principles of Java was to completely get rid of pointers because of all the dangers and hassles associated with them.

small standard library -- Many of these problems can be fixed if you want to design really safe dynamically sized data types, smart pointers. However this is real hassle to do in c in a bug free way. It would be much cooler if c could just give you functions that create data types like dynamic pointer arrays that allocate and deallocate memory by themselves. However c's whole deal (some would say appeal) is that they encourage you to use their low level abilities to write a an application specific data type from scratch. In addition pretty much anything we want to do pretty much has to be written from scratch. Want to write a cross-platform server? probably not going to happen. A document editor that also happens to need an xml parser? Sorry kid your going to have to write the parser yourself too. Most of these things have libraries, but external libraries have their own issues. Cross-compatibility, licensing, distribution complications, and an often overly complex api.

Eh i'll write up python later, but for now lets just say the concept of memory and addresses and just general obscure hardware based complications don't exist for the ordinary user.
 

Crimson King

I am become death
BRoomer
Joined
Jan 14, 2002
Messages
28,982
Python represents why our school has such a low computer science graduate ratio. Programming languages are becoming closer and closer to basic English. While Python isn't pure programming, it's getting close.

It's cool in the sense that in 10 years most programs will have to be Open Source just because it'd be easier that way, but it sucks for people waiting to get a job in it. I know at least 3 people who got degrees in it that couldn't do anything because the demand is so low now.
 

Ravener

Smash Apprentice
Joined
Jan 9, 2009
Messages
144
Location
Western Australia
Wow, thanks for Cursive and the others for being so dedicated :)
So for C is there anyway of furthur expanding the library? and could you also do that with python? But does the complier come with the language? (sorry for all the noobish questions)
 

Big Sean

Smash Journeyman
Joined
Jun 3, 2003
Messages
484
Location
Berkeley
There's no way to to change the c standard library since its standard is dependent on two groups, ISO and ANSI, and they are very resistant to changes in general. This is also pretty reasonable however because that means if they added a bunch things that needed to be in the standard library, then all of the different hardware I was mentioning would also have to include it in their compilers as well. For many c applications this might be overkill since their are probably few microcontroller applications that need to run an html server or whatever library was added to the standard. If you write in c you will definitely have to use some external library at some point. Sometimes this is not too bad because the library might be ubiquitous. For instance writing a video game using directx isn't too bad because all windows users have directx. Also most operating systems have their own extensions to the c library that are standard. Unix operating systems have the posix header, and windows has the windows header. But of course when using any of these libraries you have to remember that it will never work on any other type of operating system without the aid of an emulator. There are cross-platform libraries also but you have to specifically be looking for them, and using them doesn't automatically make your code cross-platform. The biggest deal about using these libraries however is that unless the library is wildly popular you are probably going to have to include the library with your distribution, and with that also include some sort of installation capabilities for the user. In a problem that's a lot more serious when you ship your code with other people's code you have to agree to release it under their terms. Some of these libraries like qt, require you to release your code to the public (meaning that you essentially can't make money off of it) or pay them a large sum of money for the proprietary version. The more external libraries you have the higher the chance that these libraries will conflict, or at the least the more terms your code is subjected to.

The question about compilers coming with languages is one I used to get confused about as well. A language is just a specification. Its a specification for a text file, and a specification for the behavior of the of the interpretation of that text file. Essentially a language is just a set of rules that say "You must start with the word int followed by main followed by left parenthesis etc ... " So you can go on to notepad right now and if you followed the rules given by the ANSI/ISO people then you have written valid c. You don't need a compiler or anything. Anyone is free to write a compiler and because of that their are many. Once you have notepad and any one of these many compilers you can write c code, and then compile it into binary.

Python does not have a compiler. And you may be asking two questions, 1 "If the computers can only understand ones and zeroes then how can it possibly run code that isn't turned into ones and zeroes?", and 2 "why not have a compiler since they are so awesome?" To answer the first question imagine a video game where you type in commands, and if it is in a certain format, and it does what you tell it to. For instance you might type "print 'hello world'" and it prints the words "hello world" onto your screen. This is whats called an interpreter. Its a program that reads in commands and does what it is told. Because the computer now has to run the interpreter code, AND the the code that the interpreter is running, interpreted languages run slower than compiled languages. If all the language had to do was run print commands then interpreted languages would be negligibly slower than compiled ones. However interpreted languages don't exist just to be slower versions of compiled languages, they exist to exploit and abuse the interpreters. For instance in c you have a 32 bit integer. This means that the largest number you can hold is 2 ^ 32 - 1. This means that if you wanted to calculate 12 factorial, your c code would return the wrong answer because it simply can't hold a number that big. If you wanted to be really clever you could create a complicated data type that represents an infinite precision integer by allocating memory on the fly, but it would be difficult to implement a fast, efficient data type, and the syntax would not be as easy as x = factorial(12). What the interpreted languages say is "let the interpreter do all of this complicated work, the programmer should be able to program without all of the complications that have to do with the machine. " So in python you can totally say x = factorial(1000) and its all good (as long as you have enough ram!) In python you also pretty much allocate as much memory as you want and never have to worry about returning it. The interpreter runs a program called a garbage collector that does all the hard work for you. This garbage collector is probably the slowest part of the interpreter's job. But interpreted languages aren't just about making doable things easier, they are also used for writing code that is pretty much impossible to write in a compiled language. I'll mention these when I write up the advantages/disadvantages of python.

So probably the biggest question is "So really how slow is python?!", the answer is that it can be up to 1000 times slower than c. So why does this not worry me and the interpreted language fans around the world? Partially because computers are so fast anyway. A 1.5Ghz computer can add two numbers in c in about .7 nanoseconds. That means that in python its about 7 microseconds (this isn't really true, but lets say all 1 clock operations in python took 1000 clocks) Going from one ridiculously small number to another ridiculously small number doesn't upset me too much. The other reason has to do with the kinds of programs we write. I implore you to look at what's going on your desktop right now. There's probably a webbrowser up, thats doing nothing but waiting for you to move the scroll bar, which is a miniscule operation, and you have your music player who's processing is mostly handled by your sound card. If your look at how your computer is performing, you might see that firefox is taking a significant part of your memory, but that your cpu usage is well under 30%. This is a big secret about computers, that at almost all times it is running its really doing nothing. Now what I don't want to suggest is that this is reason enough to add a huge load to your computer because of python. What I do want to suggest is that if you write you programs correctly, their will be very little python code running in the first place. These are the kinds of applications that python is good for. Their are other applications that require a computer to be running at full juice, this is where you want to also have another language in your back pocket.

To further complicate your understanding I will bring you into the current and future state of programming. All of the major python interpreters don't immediately read text and run it. Instead they compile their code to an imaginary machine. This is called a Virtual Machine or a VM. In python this "bytecode" is the actual code that can be interpreted. This is also what java, c#, and all of the .NET languages do, including c/c++, except they go one step forward. Instead of running the code immediately they actually compile some parts of the code, as its running! So the code becomes about as fast as compiled code. This is called Just in time compiling (JIT). Jython, and IronPython also do this automatically. The defacto python standard CPython also has an extension module called psyco that does this by adding a whopping two lines of code to your file. As mentioned before some parts of python can't really be compiled effectively so the gains aren't really as great as the other JIT languages, but it can easily make your code run 10 times faster.
 

Ravener

Smash Apprentice
Joined
Jan 9, 2009
Messages
144
Location
Western Australia
I think I'll stick with python because it has object orientation and thats the kind of stuff i'm looking to learn so thanks for all the help and i'll probably update the post later on when i need further help.
 

Big Sean

Smash Journeyman
Joined
Jun 3, 2003
Messages
484
Location
Berkeley
Yeap, but you'll see object oriented programming for the rest of your life. Object Oriented programming was added late in the design of python I think partly because it was a very trendy thing to do at the time. Python at its core is not really about OO its about the interface between imperative and functional programming in a simple way. You'll see what this means one day hopefully :) Good Luck! and check out pygame if your interested in making video games.
 
Top Bottom