LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 11-22-2008, 02:38 PM   #1
jman11
LQ Newbie
 
Registered: Nov 2008
Posts: 9

Rep: Reputation: 0
Python or C for semi-newbie?


Sorry for asking the standard "which language first?" question, but I have a slightly different slant. Also, I apologize for the long post, but I figure the more specific I can be, the easier it will be for others to provide feedback - and avoid another language war ;-)

I have some experience programming - I've used PHP to develop some basic database driven websites and modify Wordpress, worked through one of those "Java in 5 second books," and have hacked around a bit with Python and C. So I understand the basic concepts of OO programming, for/while loops, if / then statements, etc. My knowledge lacks in the areas of data structures, writing efficient code, and more complex topics.

I now want to "master" a language, both for practical development purposes and to establish a firm grasp of programming. I am specifically interested in server-side / web, natural language processing, AI, and data (economic and financial) analysis.

Python appears to be a great choice for this, though I know with AI and data analysis there can be some massive number crunching that may require dropping down into C.

My gut is to start with Python, but many of the good programmers I know learned C / C++ first. My sense is that learning the lower level language first gave them a deeper understanding of what was going on "underneath the hood" and therefore when they moved to higher level languages, they picked them up extremely quick and were able to write more efficient and eloquent code.

On the other hand, I may be able to learn these same things in Python without having to worry about memory management, buffer overflows, etc.. Then, when I need to learn C, I would do so already having a good handle on some of the topics I am currently weak on.

Thoughts?
 
Old 11-22-2008, 04:01 PM   #2
CRC123
Member
 
Registered: Aug 2008
Distribution: opensuse, RHEL
Posts: 374
Blog Entries: 1

Rep: Reputation: 31
Quote:
Originally Posted by jman11 View Post
My gut is to start with Python, but many of the good programmers I know learned C / C++ first. My sense is that learning the lower level language first gave them a deeper understanding of what was going on "underneath the hood" and therefore when they moved to higher level languages, they picked them up extremely quick and were able to write more efficient and eloquent code.
IMO, you are right on with this idea. C++ was the first programming language I learned (aside from VB in high school) and I do believe that knowing c and c++ gives you a tremendous advantage when trying to learn a new language and how to write efficiently. When trying to do data structures, Object Oriented programming languages are the way to go(aka C++ and java). Java is a bit easier to learn, but I still prefer C++.
 
Old 11-22-2008, 04:29 PM   #3
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,858
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

I think C is wonderful, and I'd encourage any developer on any platform to learn and use good, old fashioned C.

But that's not really your question.

The real answer to the question "Python or C++ for OO for a semi-newbie?" is:
Quote:
It depends.
It depends:
a) on the task (the right tool for the right job)
b) your personal inclinations
But all things being equal ... between C++ and Python ... I'd vote for Python. Hands down. It's cleaner, it's arguably a *lot* easier, and, arguably, the resulting Python code is almost always a lot better than the C++ equivalent.

IMHO .. PSM

Last edited by paulsm4; 11-22-2008 at 04:33 PM.
 
Old 11-22-2008, 04:43 PM   #4
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 49
I really don't think it matters which language you learn first; in another thread someone posted that it takes a week to learn the fundamentals of a new language and I absolutely agree. I have had to learn new languages just to support ongoing work - no one is going to spend the time to translate 20+ years of work into your favorite language.

What *is* important is that you understand the concepts used in programming. I'd say ideally you should learn a little about the theory of computation and if you can find an ancient book on the subject you'll have less than 200 pages to read though - but that would be some of the most basic and most important stuff and would not have changed at all over the years. Then I think it's good to have some idea of how those concepts are put to use in hardware. For this part I think Don Knuth's series "The Art of Computer Programming" does a great job. If you can read through the entire series and do all the exercises you'll be ready to tackle most jobs. Of course the series doesn't cover *everything* - that's just not possible - so as far as I know there are no sections on graphical rendering and such.

The main thing is that simply knowing the keywords and syntax of a programming language does not make you a good programmer; there's an awful lot more to learn. At least when you're starting out it's not unusual to write a lot of code and in the future decide it was all garbage and throw it all away and start again. As you improve your skills you'll find less reason to throw away your work. I'm still happily throwing away other people's work though - mostly the work of people who think that learning the keywords and syntax make them a programmer - there's an oversupply of such people I'm afraid, and they produce the most awful code imaginable especially as they're influenced by the 'book du jour' of programming and haven't even got a consistent style.
 
Old 11-22-2008, 05:50 PM   #5
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 46
I'd suggest learning C, then python, then C++: that's the path of increasing conceptual complexity.

Writing good C is tricky at first, but the language has fewer moving parts than python. Notable exceptions are unions, the keyword 'static', and the explicit use of pointers. In turn, python have fewer moving parts than C++.

To learn C, use "The C programming language" by Kernighan and Ritchie [or find a tutorial on the web]. Do the exercises you find interesting; enough that you feel confident you got a good grasp of the language. Get used to passing (pointers to) structs around to functions. Get used to function pointers. Learn how to use qsort and bsearch correctly. learn about binary search trees (they're in the book), and splay trees*. implement a splay tree data structure, with a user-specified comparison (hint: function pointers).

(* the book talks about self-balancing binary search trees. Splay trees are the simplest to implement; alternatives are red-black trees [they're a bitch to get right] and AVL trees [less so]. A downside is that splay trees are a little slower in practice, and the theoretical speed equivalence is only amortized).

Then move on to python. Read "how to think like a computer scientist: learning with python". A lot of stuff should be familiar from C; a little bit should be new. Passing objects around explicitly should be familiar, as should passing around functions. Learn how inheritance, operator overloading, exceptions and modules work.

Then move on to C++. Operator overloading and exceptions works similarly, namespaces work roughly similar to modules. Inheritance requires judicious use of the keyword "virtual" to work properly, but is otherwise similarly. References are going to be new, as are templates and access rules (public/protected/private). Adapt the splay tree from C to store objects of a template type, and implement all the methods of std::set. Make good use of public and private members; use nested classes. Learn about smart pointers, and in particular reference counting ones; it'll make object deallocation much easier.

A good exercise is to write object-oriented code in C, with pointers to vtables and superclass instances as struct members (and optionally pointers). It'll give you a good sense of how C++ works under the covers.

Performance hints: if disk access or network bandwidth are your major performance limiters, and/or n is small, it's safe to go with python. If you start writing things in python and discover a performance bottleneck, you can write python modules in C. That may or may not be good enough. Measure first
 
Old 11-22-2008, 06:59 PM   #6
cmnorton
Member
 
Registered: Feb 2005
Distribution: Ubuntu, Red Hat
Posts: 571

Rep: Reputation: 34
Order is Dependent

When C++ tools first became commercially available, at least on Windows, most of us had already learned C. We were told then that it would be easier to learn C++ because after all we had a C background. We were also told that learning C++ would be difficult, because we had a function-call mindset. Both observations were correct.

Thinking about objects, for me, took a complete virtual 90-degree rotation of my mind. I had programmed firmware using Bliss and VAX Assembler, not the stuff used to create objects, and worked on networking software, not necessarily the first area you would think of to implement C++.

This is what I would do:

If you have to learn one of these languages, because of a need, school project, work, etc, learn that. Else, learn C++ first. Don't learn it as a "better C"; that was a rubbish reason given to us to encourage moving to C++; a lot of developers did not want to use it way back when.

Edit
I suggest learning C++ first to get the object mindset strongly in the way you do things.
End Edit

Regardless of the language you use, learn what you need to use as a tool, how its implementation will affect execution speed, and how long you expect the code to be running.

I have worked on public sector database projects for nearly five years now. Most of the time Informix's 4GL code is fast enough. However, when I chose to add an interactive link from a 4GL application over to an address verification application whose link was http protocol, I implemented it in C.

Last edited by cmnorton; 11-22-2008 at 07:04 PM. Reason: add more info
 
Old 11-22-2008, 07:00 PM   #7
jay73
Guru
 
Registered: Nov 2006
Location: Belgium
Distribution: Ubuntu 11.04, Debian testing
Posts: 5,019

Rep: Reputation: 128Reputation: 128
Quote:
My gut is to start with Python, but many of the good programmers I know learned C / C++ first. My sense is that learning the lower level language first gave them a deeper understanding of what was going on "underneath the hood" and therefore when they moved to higher level languages, they picked them up extremely quick and were able to write more efficient and eloquent code.
That would all depend on the learning materials used. If you take "Teach Yourself C/C++ in 24 hours", you may actually learn more from a good Python manual.
Also I would not take it for granted that learning C/C++ makes your more efficient and eloquent in other languages. I took C++ after Java and Python and looking back on it, I can say with confidence that it did not teach me all that much that was of practical value for coding in Java/Python (which is not to say C++ is not powerful, on the contrary - it is just that most of what makes it powerful does not (easily) translate into another language).

Last edited by jay73; 11-22-2008 at 07:05 PM.
 
Old 11-22-2008, 07:06 PM   #8
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,123

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407
I would suggest to learn both Python and C/C++ in parallel.

And among scripting languages Python is not the cleanest one conceptually. And maybe not the most efficient.

Ruby would be cleaner; Lua simpler and maybe cleaner.

As I said in a different thread, Python lacks proper scoping and closures, and this makes it a non-starter for me.

C/C++ at least have proper scoping, and GNU C even has kind of closures - one can declare and implement a function inside another function.

I stick with Perl - and maybe they'll finally implement Perl6 - that beast is _really_ interesting because of a lot of paradigms and features to be present.
 
Old 11-22-2008, 07:15 PM   #9
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: back to Arch
Posts: 16,689

Rep: Reputation: 427Reputation: 427Reputation: 427Reputation: 427Reputation: 427
disclosure: I am not a programmer.

(But I still have opinions....)

I take the old-fashioned view: Learn first the simplest, most powerful, and least forgiving, before learning things that either add layers of difficulty and obfuscation, or attempt to make things easier. To me, this means learn C first.

Python makes some stuff so easy that you might never learn to worry about data types, etc.

Having first struggled to learn C, I can't imagine piling on the OOP layer to make C++, and trying to learn it all at once.
 
Old 11-22-2008, 07:29 PM   #10
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,123

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407
Quote:
Originally Posted by pixellany View Post
disclosure: I am not a programmer.

(But I still have opinions....)

I take the old-fashioned view: Learn first the simplest, most powerful, and least forgiving, before learning things that either add layers of difficulty and obfuscation, or attempt to make things easier. To me, this means learn C first.

Python makes some stuff so easy that you might never learn to worry about data types, etc.

Having first struggled to learn C, I can't imagine piling on the OOP layer to make C++, and trying to learn it all at once.
On the one hand I agree with you.

On the other, knowing just C forces you sometimes to write complex programs for problems easily solved by a scripting language, especially a high level one like Python/Perl.

I.e. one must know elastic arrays and hashes exist, but one must also know the cost of implementing them, and looking into a C library which does the implementation is quite revealing.

I am not a programmer by education, but in the last 20 years I've doing mostly code, even it was HW design.
 
Old 11-22-2008, 08:19 PM   #11
jman11
LQ Newbie
 
Registered: Nov 2008
Posts: 9

Original Poster
Rep: Reputation: 0
Wow, thanks for the multitude of great replies!

Just to clear up some confusion, I wasn't considering C++. If I am going to do OO, I'd probably go with Python and down the road, Java (given my small experience with Java). Hence why I am looking at Python and C.

Also, I don't think i have time to learn multiple languages in parallel - I am leading a serial life ;-)

To throw in another loop, I have been told for what I would like to eventually do - AI, natural language processing, data analysis, and some web / network stuff (mainly to pull down data and send back machine or human readable responses) maybe I should go with Java and forget the rest given its speed, relative easy compared to C++, available libraries, and a good teaching language.

On the other hand, I think it is generally agreed that Python (or Ruby) is usually quicker to program with vs. Java, C++, or C, easier to do more difficult tasks, and you can always write modules in C if there is a processing bottleneck.

Let me pose a different question: do I lose much by starting with Python, and then taking up C when I start to run into performance issues that require me to write some C modules?

Thanks again!
 
Old 11-22-2008, 10:05 PM   #12
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,858
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

Quote:
do I lose much by starting with Python, and then taking up C when I start to run into performance issues that require me to write some C modules?
Absolutely not. In fact, regarding cmnorton's post above (which I completely agree with) (except for the "learning C++" part ;-)), learning python first (and consequently not only getting up to speed with useful projects quicker, but also becoming comfortable with OO concepts at the same time) is probably the ideal solution.

It sounds like a great plan - go for it! And have fun!

IMHO .. PSM

PS:
Again, I definitely encourage you to learn C when the opportunity presents itself. And, as cmnorton observed, if you ever want to learn C++, do *not* approach it as a "better C". You'd be much better served learning C++ strictly from an OO perspective, and learning C by itself (on its own terms, as a very powerful - but still procedural - language).

Last edited by paulsm4; 11-22-2008 at 10:10 PM.
 
Old 11-23-2008, 04:03 AM   #13
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,352

Rep: Reputation: 129Reputation: 129
If as your original post implied you wanted "to establish a firm grasp of programming". Then I would suggest C, with the following caveat: Focus on data structures, you already have a grounding in programming so picking up the basics of C should be fairly easy (although you will need to spend time understanding pointers & memory management). Grab a copy of the O'Reily Algorithms with C [Loudon, Kyle], the first dozen chapters cover pointers, recursion and data structures and the rest of the book look at the classic algorithms.

Understand how the structures work and when to use them. Then when you decide to use Python (or Ruby) where these data structures are part of the language will know which is best to use, and why.
 
Old 11-23-2008, 04:17 AM   #14
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,371

Rep: Reputation: Disabled
Quote:
Originally Posted by jman11 View Post
To throw in another loop, I have been told for what I would like to eventually do - AI, natural language processing, data analysis, and some web / network stuff (mainly to pull down data and send back machine or human readable responses) maybe I should go with Java and forget the rest given its speed, relative easy compared to C++, available libraries, and a good teaching language.
This is mainly to satisfy my own curiosity, but with regards to data analysis, will it be strictly necessary for you to use a "regular" language (e.g. Python, C++, Java, etc) as opposed to a language/environment made for data analysis (e.g. MATLAB, IDL, R, etc)? I'm just wondering if you had considered those already or not really .
 
Old 11-23-2008, 10:26 AM   #15
jcookeman
Member
 
Registered: Jul 2003
Location: London, UK
Distribution: FreeBSD, OpenSuse, Ubuntu, RHEL
Posts: 417

Rep: Reputation: 33
Quote:
Originally Posted by Sergei Steshenko View Post
As I said in a different thread, Python lacks proper scoping and closures, and this makes it a non-starter for me.
I'd love to hear more about this.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Semi-newbie using SuSE e6003 LinuxQuestions.org Member Intro 3 01-22-2007 09:35 PM
newbie with semi clue needs help please. 0wner Slackware - Installation 2 10-25-2005 05:37 PM
Another (semi) Newbie TheMaxPower LinuxQuestions.org Member Intro 1 05-28-2005 08:02 PM
Linux semi-newbie and Wine vary newbie geovolt_os1 Linux - Software 4 04-19-2005 11:03 AM
help a semi-newbie out roYal Linux - Newbie 2 04-08-2004 02:34 PM


All times are GMT -5. The time now is 02:56 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration