New to programming

A place to discuss the science of computers and programs, from algorithms to computability.

Formal proofs preferred.

Moderators: phlip, Moderators General, Prelates

Shmifty
Posts: 7
Joined: Fri Jul 27, 2007 10:55 pm UTC
Contact:

New to programming

Postby Shmifty » Fri Jul 27, 2007 11:05 pm UTC

I'm a Linux user (have been for over a year) and I thought it I should learn some programming. I've heard Python is a good beginner language but I'm unsure if that is where I should start. Any suggestions?

User avatar
QuantumTroll
Posts: 158
Joined: Fri Jun 08, 2007 12:00 am UTC

Postby QuantumTroll » Sat Jul 28, 2007 12:45 am UTC

This is a subject of heated debate, so expect to hear a lot of different answers.

Python is high on my list of beginner languages.

I suggest you just go for it. Just don't accidentally go to pythong.org instead of python.org...

Dark Shikari
Posts: 113
Joined: Mon Jul 16, 2007 7:03 am UTC

Postby Dark Shikari » Sat Jul 28, 2007 1:12 am UTC

The first thing you should do is learn the absolute basics of C.

Almost all modern languages are based in some way off of C, and the basics of C itself, from if statements to for loops and so forth are very very easy to learn.

Once you know the basics of C and can write yourself a simple command-line C program, then you can move on to other languages to do more language-specific things. C is good because you can do so much without language-specific code; I can write a program in C and port it to Java or any other C-style language in mere minutes.

Don't spend too much time in C though; you want to avoid learning the esoterics of individual languages early on in the learning process.

Shmifty
Posts: 7
Joined: Fri Jul 27, 2007 10:55 pm UTC
Contact:

Postby Shmifty » Sat Jul 28, 2007 1:25 am UTC

So basics of C with added Python for a good start? Sounds good to me, thank you.

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Postby EvanED » Sat Jul 28, 2007 1:46 am UTC

QuantumTroll wrote:Just don't accidentally go to pythong.org instead of python.org...


Damn you. ;-)

Just to add my voice, I'm not convinced that C is the right beginner's language. I'm not convinced it's not, but I don't think it's right. There's too much crap you have to deal with, especially with the atrocity that is C string handling. I might even go so far as to say that C++ is better because, if you have a good 'teacher' (person/book/website/...), it will block you from a lot of the things that make C frustrating. But I'm not convinced of that either, because C++ is also a lot more complicated than C. Even if you restrict yourself to just the C-like subset of C++ plus things like std::string and the rest of the STL, there are still some non-trivial corners.

I don't know what to suggest, but I personally think something that's rather higher level than C.

It also depends on what you want to get out of it. If you just want to be able to write the occasional quick script, then I would say that Python is almost certainly your best bet, and by a noticeable margin. If you want to get into the computer science bit, and learn the nuts and bolts of how computers work and how programming languages work and stuff like that, the 'start with C' approach takes on a lot more merit because it will force you to learn that stuff. (Edit: But I think there would still be a lot to be said with either starting with the "better C" way of looking at C++, or else go an entirely different route and look at Scheme or ML.) If you're looking to learn a marketable skill as quickly as possible, maybe Java is where you should look, though this is said with reservation.
Last edited by EvanED on Sat Jul 28, 2007 2:41 am UTC, edited 1 time in total.

User avatar
yy2bggggs
Posts: 1261
Joined: Tue Oct 17, 2006 6:42 am UTC

Postby yy2bggggs » Sat Jul 28, 2007 2:31 am UTC

EvanED wrote:
QuantumTroll wrote:Just don't accidentally go to pythong.org instead of python.org...


Damn you. ;-)

Just to add my voice, I'm not convinced that C is the right beginner's language. I'm not convinced it's not, but I don't think it's right. There's too much crap you have to deal with,


The problem is, many people don't believe you.

They should perhaps read this:
http://www.research.att.com/~bs/new_learning.pdf

...and I'm just going to get more evil about this as time goes on (I'm in the middle of a severe effort to collect references; no, it's not just to be an ass on this forum--it's to be an ass elsewhere, but I'm glad to share).

Edit: In case this wasn't obvious, this is a second vote for C++ over C. For what it's worth though, I don't preach C++ as the end all of languages; it's just what I know best. Specifically, I'm not claiming C++ is the best language to start in, but it's not a bad one by any means.

As much as people may be tempted to rip into me, I'll even claim that basic and pascal are good beginner languages.

zenten
Posts: 3799
Joined: Fri Jun 22, 2007 7:42 am UTC
Location: Ottawa, Canada

Postby zenten » Sat Jul 28, 2007 4:21 am UTC

Python will be easier to learn, and is a perfectly good language to do all sorts of "real" stuff with. C is harder to learn, however, a lot of the things that make it hard also make it fast, and thus it does have some real advantages in some areas over Python.

What I would recommend is learn "programming" in Python. Then once you're comfortable being able to actually make programs that do stuff, look at other languages. C would be a good one, since you can combine it with Python to make faster Python programs in rather easy ways. It is also probably the oldest language that is still in very common use, which actually has some upsides.

Then after that you would want to start looking at either programming languages that would help you get a job, or ones that force you to think in completely different ways (sometimes those can be the same language too). But that would be awhile from now.

Shmifty
Posts: 7
Joined: Fri Jul 27, 2007 10:55 pm UTC
Contact:

Postby Shmifty » Sat Jul 28, 2007 4:37 am UTC

Well I'd only be using it for small Linux programming like modifications to pre-existing KDE/python based program if that changes which language I should be learning (well at least I know I need to learn Python to a certain degree).

zenten
Posts: 3799
Joined: Fri Jun 22, 2007 7:42 am UTC
Location: Ottawa, Canada

Postby zenten » Sat Jul 28, 2007 4:56 am UTC

Shmifty wrote:Well I'd only be using it for small Linux programming like modifications to pre-existing KDE/python based program if that changes which language I should be learning (well at least I know I need to learn Python to a certain degree).


You'd want Python, C and C++ then, with some Perl to boot (assuming it doesn't make your eyes bleed).

Shmifty
Posts: 7
Joined: Fri Jul 27, 2007 10:55 pm UTC
Contact:

Postby Shmifty » Sat Jul 28, 2007 5:13 am UTC

Where is a good resource for Python programming?

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Postby EvanED » Sat Jul 28, 2007 5:29 am UTC

I hear this is good.

Shmifty
Posts: 7
Joined: Fri Jul 27, 2007 10:55 pm UTC
Contact:

Postby Shmifty » Sat Jul 28, 2007 5:42 am UTC

This forum really is helpful.

platypus01
Posts: 101
Joined: Sat Jul 28, 2007 6:50 am UTC

Postby platypus01 » Sun Jul 29, 2007 7:38 am UTC

Maybe this will help you, maybe it won't. When I started teaching myself programming, I started with C, with K&R (2nd ed). This was good and bad.

It was good, because, by having been around *nixes and programming folks, I picked up a good bit of the "programming" jargon, and some others I was able to quickly gather the meanings of from context. It helped me understand what the program was doing, blah blah blah (the usual deal).

It was bad, because some of the stuff I had absolutely NO CLUE about, and I'd read and reread it over and over again, failing to discern its meaning. Which was very frustrating. As a result, often I'd take a "break" from learning C, often for weeks (months?) at a time. My learning of C was very spread out over quite a large amount of time, during which I'd revolve those ideas I couldn't grasp around my head, trying to figure it all out. Eventually, it all sunk in, and though some parts I'm still hazy on, I'm for the most part not incredibly bad at C now.

Just saying, you might run into some unfamiliar concepts. In my experience, these things just take some time to get used to. Maybe not so much for you, I don't know, but it did for me. So just watch out for them.


On another note, I've been meaning to learn FORTH. I hear if you try to learn it knowing another language, you'll have to forget all about what you know or something (cause it's so different or something). OTOH forth is kinda dead now... :cry:
bleh

User avatar
FiddleMath
Posts: 245
Joined: Wed Oct 11, 2006 7:46 am UTC
Location: Madison, WI
Contact:

Postby FiddleMath » Sun Jul 29, 2007 8:54 am UTC

I'll go out on a limb here: Python is the right sort of language to know about 90% the time. It's comparatively easy to learn, has a fairly small but powerful syntax, and is paradigm-flexible, while still being quite concise. Object-orientation is built-in pretty deeply, but you don't really have to worry much about it if you don't need it. It can do some of the things that make functional programming awesome, though sometimes this is a little clunky. Python has an excellent set of standard modules for doing lots and lots of tasks - image processing, database access, web tools, parsing lots of kinds of files in lots of ways, etcetera...

However, the really awesome stuff - graphics intensive programs like games or video editing; system software, and software that needs to chug through hard computational problems - probably shouldn't be in Python, it's too noticeably slow.

If you just want to know enough programming to better control tasks on your computer, maybe do some web stuff and clever automations, then learn Python.

If you want to really grow into programming, over the course of a few years (or maybe some really intense months), learn Python first, and then take C, and then learn a dialect of Lisp.

C forces you to think about a lot of details that other languages automate away; this means that you eventually understand them deeply - with background in C, the basic forces behind the abstractions that higher-level languages employ become clearer. Plus, C is still the lingua franca of a lot of really cool application area, demanding performance and closeness to the machine.

Lisp, on the other hand, is a mind-altering experience, even for a programmer well-seasoned in C, Python, or their kin. Lisp may be worth learning if only because it is so vastly different from C: once you can code in both C and Lisp, you can probably learn any other programming language rapidly.

If you have a strongly mathematical/theoretical inclination, you might want to do Lisp first, then C. If you have a strong inclination to groove with your underlying hardware, you might want to learn C first, then Lisp.

But this isn't the way I learned programming: I'm imagining the way I would've preferred to learn. I haven't really taught programming to anyone, either, so read this with a small quantity of sodium chloride. (But, then, how many of y'all giving advice have tried teaching new programmers? How many have tried more than one starting language?)

zenten
Posts: 3799
Joined: Fri Jun 22, 2007 7:42 am UTC
Location: Ottawa, Canada

Postby zenten » Sun Jul 29, 2007 2:18 pm UTC

I learned first with Commodore Basic, and then Turing (and then OOTuring). Not a route I would recommend either.

User avatar
blackeye
Posts: 105
Joined: Mon Jul 30, 2007 4:41 am UTC

Postby blackeye » Mon Jul 30, 2007 4:43 am UTC

I'm learning python as my second (really first) language.
right now I'm using this http://en.wikibooks.org/wiki/Non-Progra ... for_Python
it's a pretty nice tutorial to help you get the feel of things

iw
Posts: 150
Joined: Tue Jan 30, 2007 3:58 am UTC

Postby iw » Tue Jul 31, 2007 5:15 am UTC

Shmifty wrote:Where is a good resource for Python programming?

Python Essential Reference is basically the K&R (i.e., a concise, useful, well-written reference) of Python.

Shmifty
Posts: 7
Joined: Fri Jul 27, 2007 10:55 pm UTC
Contact:

Postby Shmifty » Tue Jul 31, 2007 5:46 am UTC

Wow I love Python, its so clean and powerful. I actually wrote an amortization program earlier today just to test my progress and I had it finished within an hour. I hope that I will actually be able to start doing helpful programming soon. Thanks to everyone who posted in this topic.

User avatar
Large Trout
Posts: 13
Joined: Tue Aug 07, 2007 6:49 pm UTC

Postby Large Trout » Tue Aug 07, 2007 7:56 pm UTC

I learned Java as my first language at University. This was about 7 years ago now and I've forgotten most of it (the language itself has changed a hell of a lot since then anyway). I'm currently relearning it and I have to say it's a very powerful language and has a good set of libraries with which to work from easily.

I'd recommend learning Java. It ebbs and flows in popularity (some loath it but others love it), but it has many features to it that you can learn; for example, you can make Windows/Linux/Mac applications, Web applications/servlets/applets, games (although it's not too great for making games), programming for databases, etc.

wady_kernels
Posts: 2
Joined: Sun Aug 05, 2007 4:40 pm UTC

Postby wady_kernels » Tue Aug 07, 2007 9:09 pm UTC

Shmifty wrote:Where is a good resource for Python programming?


http://swaroopch.info/text/Byte_of_Python:Main_Page

User avatar
Amnesiasoft
Posts: 2573
Joined: Tue May 15, 2007 4:28 am UTC
Location: Colorado
Contact:

Postby Amnesiasoft » Wed Aug 08, 2007 1:38 am UTC

Well, you can't quite go the way I did it, but you can just skip the first step :P

I started doing programming stuff using Multimedia Fusion (which almost all programmers look down upon for some reason). It actually helps you learn the logic behind the program you're working without worrying about all the little details. Though you can't use it, Windows only.

Then I did some work on my calculator using BASIC, again, most people aren't going to recommend you do this :P

After that, I learned C and C++ at about the same time, and then took Computer Science at my school (Java).

Overall, that seems to have actually worked quite well for me.

User avatar
b.i.o
Green is the loneliest number
Posts: 2519
Joined: Fri Jul 27, 2007 4:38 pm UTC
Location: Hong Kong

Postby b.i.o » Wed Aug 08, 2007 4:49 am UTC

Amnesiasoft wrote:Then I did some work on my calculator using BASIC


Oh come on, who didn't? :)

User avatar
taggedunion
Posts: 146
Joined: Fri Jul 06, 2007 6:20 am UTC
Location: BEHIND YOU

Postby taggedunion » Wed Aug 08, 2007 8:12 am UTC

Silver2Falcon wrote:
Amnesiasoft wrote:Then I did some work on my calculator using BASIC


Oh come on, who didn't? :)


*sits on hands*

Anyway, I totally endorse Python. It is my go-to language along with C.

C is a good one to learn eventually, but I'm not going to lie that it's going to cause you a great deal of pain and heartache. If you learn Java first -- and as much as I dislike Java, it's an important language to know -- you can get the feel of syntax/look and structure of a C-like language under your belt. For me, I think the big "aha" moment for C is understanding pointers & references. Once you have that, everything else is easy.*


* Except memory management -- which I don't think EVER gets easy.
Yo tengo un gato en mis pantelones.

User avatar
djn
Posts: 610
Joined: Mon May 07, 2007 1:33 pm UTC
Location: Oslo, Norway

Postby djn » Wed Aug 08, 2007 12:40 pm UTC

The odd thing with C is that pointers seem like such a trivial idea when you finally get it. It makes it hard to give long enough explanations to the new people.


The basic idea is just this: A variable contains a value. It's stored somewhere in memory.
A pointer is that address in memory.

If you call a function with a variable as an argument, the value is sent. The value of a pointer is the address. Thus:

Code: Select all

int a = 5;
int *b = &a; // b is a pointer to an int. It now contains the address of a.
// Let's say "a" is stored at 0x1234 in memory.

func(5); // the function will get the literal value 5
func(a); // the function will get the literal value 5
func(b); // the function will get the literal value 0x1234


In the last function call, it is possible for the function to go to the given address, look at the value (5), and then change it. In the other two cases, it wouldn't know where to write the changed value.
It's not magic, though: You'll have to know if you're receiving a value or an address when you write the function.

If you've got data that is larger than what you can fit in a register on your CPU, such as an array of some sort, the only way to pass it around is to send the address of it: A pointer.
Ditto with memory allocation: If you ask for a chunk of memory, you get a pointer to the start of it back.

If you think you can make sense of this, C is worth playing around with.
Otherwise, it might be better to get the general ideas down in a language that hides this first, so you can tackle one problem at the time.

EvanED
Posts: 4331
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Postby EvanED » Wed Aug 08, 2007 1:06 pm UTC

djn wrote:The basic idea is just this: A variable contains a value. It's stored somewhere in memory.
A pointer is that address in memory.


I have a friend who once said that he doesn't understand why people think pointers are so hard to get. "You don't get your house confused with your address."

If you've got data that is larger than what you can fit in a register on your CPU, such as an array of some sort, the only way to pass it around is to send the address of it: A pointer.


You can pass structs by value too. ;-)

User avatar
WhiteRabbit
Railgun of Infinite Patience
Posts: 242
Joined: Fri Oct 20, 2006 2:30 pm UTC
Contact:

Postby WhiteRabbit » Wed Aug 08, 2007 3:07 pm UTC

Python is a wonderful language, not only for beginners but also for almost all types of programming. I highly recommend it as your first language. Sure, you will need to pick up C/C++ at some point, but python is a great place to learn to think about program design rather than learn to deal with a bunch of obnoxious syntax and deal with cryptic compiler error messages.
For the Jihad

User avatar
djn
Posts: 610
Joined: Mon May 07, 2007 1:33 pm UTC
Location: Oslo, Norway

Postby djn » Wed Aug 08, 2007 3:08 pm UTC

EvanED wrote:You can pass structs by value too. ;-)


Gods, that's evil. How/when/why? And how does that work with the arguments-in-registers style of function calls?
(I can see it work if you do BSD style arguments-on-stack, but ...)

Rysto
Posts: 1460
Joined: Wed Mar 21, 2007 4:07 am UTC

Postby Rysto » Wed Aug 08, 2007 3:50 pm UTC

When you're passing structs by value, you have to pass them on the stack. You can also return structs by value. Don't ask me how that works, though.

iw
Posts: 150
Joined: Tue Jan 30, 2007 3:58 am UTC

Postby iw » Wed Aug 08, 2007 4:53 pm UTC

djn wrote:Gods, that's evil. How/when/why? And how does that work with the arguments-in-registers style of function calls?
(I can see it work if you do BSD style arguments-on-stack, but ...)
Same way it works for functions with like a zillion arguments, I would assume.

iw
Posts: 150
Joined: Tue Jan 30, 2007 3:58 am UTC

Postby iw » Wed Aug 08, 2007 5:01 pm UTC

EvanED wrote:I have a friend who once said that he doesn't understand why people think pointers are so hard to get. "You don't get your house confused with your address."

I remember when I started learning C, and the confusion came out of stuff like: int *p vs *p = 4, when to use &x vs. x, and pointers-to-pointers. I didn't really get pointers until I had to program an OS for class in university.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11129
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Postby Yakk » Wed Aug 08, 2007 5:40 pm UTC

djn wrote:
EvanED wrote:You can pass structs by value too. ;-)


Gods, that's evil. How/when/why? And how does that work with the arguments-in-registers style of function calls?
(I can see it work if you do BSD style arguments-on-stack, but ...)


To implement C, you need to be able to support arguments on stack when you run out of registers.

User avatar
WhiteRabbit
Railgun of Infinite Patience
Posts: 242
Joined: Fri Oct 20, 2006 2:30 pm UTC
Contact:

Postby WhiteRabbit » Wed Aug 08, 2007 7:34 pm UTC

iw wrote:I remember when I started learning C, and the confusion came out of stuff like: int *p vs *p = 4, when to use &x vs. x, and pointers-to-pointers.


That and the difference between x.y and x->y tripped me up in the beginning. The concept is pretty obvious, but the syntax confuses the issue for newbies.
For the Jihad

User avatar
taggedunion
Posts: 146
Joined: Fri Jul 06, 2007 6:20 am UTC
Location: BEHIND YOU

Postby taggedunion » Wed Aug 08, 2007 8:25 pm UTC

I'd argue that one needn't worry too much about passing args on the stack in a RISC language, but then the conventions only usually reserve 4 argument registers (well, in MIPS at least).

Y'know, 4 dedicated argument registers as opposed to, like, 8 registers overall.

I really don't understand why Intel for so long has wanted to keep backwards compatibility for systems with such dearths of registers.


Back on topic, I totally understand the pointers thing in hindsight. It's like, "this is so obvious? why didn't I think of this before?", but before you get it, it's so hard to smack through your brain. Well, for some people at least. I'm glad I already have the Big 3 of CS education already: pointers & references, data structures, and recursion.

And passing a struct on the stack is quite useful. It avoids making a local malloc, returning the pointer, and worrying about having to deallocate said pointer. If you pass it on the stack, it stays automatic -- and that's certainly nice.

Not like I've ever had a need to use this, but I can see why it's allowed.

Oh, and as much as I know the why and how of x.y vs. x->y, I really hate the arrow notation, mostly because of the 3 awkward keystrokes. You would think of all the stuff the compiler does automatically, it could figure out whether and how many pointer dereferences it needs. D manages fine with that, fo' sho'. And I really don't like that PHP had to borrow the arrow notation. Oy.
Yo tengo un gato en mis pantelones.

User avatar
Peshmerga
Mad Hatter
Posts: 2061
Joined: Wed Oct 04, 2006 1:56 am UTC
Contact:

Postby Peshmerga » Wed Aug 08, 2007 9:35 pm UTC

I've been learning C++ off and on for a few months; I understand the basics of C++ programming, although I haven't gotten into much OOP. I want to learn to mod / write games (including modding Source); would I be wasting my time getting into Python?

Also; best environment to learn programming is, apparently, Linux. Should I dive into dual boot or stick with XP and use MSVC++ to learn? I want to learn to do everything from the ground up, so as to not take shortcuts around anything.
i hurd u liek mudkips???

User avatar
taggedunion
Posts: 146
Joined: Fri Jul 06, 2007 6:20 am UTC
Location: BEHIND YOU

Postby taggedunion » Wed Aug 08, 2007 10:11 pm UTC

The Debian family is great for developers and its package manager is the best (and first) of all the Linuces. Ubuntu is probably the better choice for most users from that family, though I'll stick with my straight Debian. I dual-boot Debian and XP Pro on my main compy and Mac OS X and XP on my lappy.

Learning any programming language is not a waste of time (unless it's COBOL ;-P). As far as Python goes, it's definitely not a waste of time. In *NIX systems now Python is used a lot for systems programming & scripting and a great deal of people and companies use Python. It's also greatly easier to use than C++ -- no worrying about pointers/references, memory management, virtual functions, and all that great variety of crap (not saying those aren't important -- I'd just rather not deal with them if possible).
Yo tengo un gato en mis pantelones.

User avatar
djn
Posts: 610
Joined: Mon May 07, 2007 1:33 pm UTC
Location: Oslo, Norway

Postby djn » Wed Aug 08, 2007 10:32 pm UTC

Ok, I can see how you'd implement structs by value on the stack, when you say it. I don't have to like it, though. ;)

GMontag
Posts: 209
Joined: Mon Apr 16, 2007 5:47 am UTC
Location: Bellingham, Washington

Postby GMontag » Thu Aug 09, 2007 6:25 am UTC

Rysto wrote:When you're passing structs by value, you have to pass them on the stack. You can also return structs by value. Don't ask me how that works, though.


It's pretty simple. You just grow the stack by sizeof(return type) before you push the return address onto the stack for the jsr. Then the called function just fills in the space before it returns and you've got your return value right there on the top of the stack.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11129
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Postby Yakk » Thu Aug 09, 2007 7:16 am UTC

djn wrote:Ok, I can see how you'd implement structs by value on the stack, when you say it. I don't have to like it, though. ;)


Fix your prejudice. It weakens you.

Mask of Destiny
Posts: 11
Joined: Thu Jul 26, 2007 9:43 pm UTC
Location: CT, USA
Contact:

Postby Mask of Destiny » Thu Aug 09, 2007 3:41 pm UTC

taggedunion wrote:I really don't understand why Intel for so long has wanted to keep backwards compatibility for systems with such dearths of registers.

Probably because these days ISA has very little impact on performance. Well I should say few register CISC vs. many register RISC, more exotic ISA types like VLIW certainly can have a noticeable impact on performance (not necessarily a positive one) as can SIMD type instructions.

I believe modern x86 processors use rename registers internally to manipulate at least some memory arguments efficiently.

User avatar
djn
Posts: 610
Joined: Mon May 07, 2007 1:33 pm UTC
Location: Oslo, Norway

Postby djn » Thu Aug 09, 2007 5:36 pm UTC

Yakk wrote:
djn wrote:Ok, I can see how you'd implement structs by value on the stack, when you say it. I don't have to like it, though. ;)


Fix your prejudice. It weakens you.


Because copying non-fundamental data types around for function calls is a good thing?


Return to “Computer Science”

Who is online

Users browsing this forum: No registered users and 7 guests