PHP as first programming language?

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

jdrietz wrote:Do you start with a language that is easier to learn and allows you to focus more on program design / logic?
Imho programming is about translating a problem into a solution.. Most problems are already halfway solved by simply choosing the right language... That is why i find it more important to know a couple of languages (and the problem domains where they are powerful) instead of knowing one language and problem domain in depth.
jdrietz wrote: Or, do you start with a language like C that demands you do everything and do it carefully, the benefit being that this will create good habits that you will then carry over to any other language you learn?
You always have to be careful and check if your solution is solving the problem. If you're referring to indentations, choosing names for functions, methods, variables, etc ... These are things you can (and should) do with every language.

Is it really an advantage that you have to think about memory management when you're thinking about a solution? Is it really an advantage that you have to think about a specific computer architecture/instructionset when you're thinking about a solution? Are these really advantages when you're a beginning programmer?
jdrietz wrote: If you don't mind, let me take a slightly different approach to my question: Does starting with a language like PHP, which is perhaps more forgiving to the newbie, makes it more difficult to later pick up a language like C because things taken for granted before are now required (i.e. memory management, declaring types, etc.)?
Why would PHP be more forgiving? A mistake is a mistake, in any language. Do you really want to think about memory management when you're generating html? Btw, with PHP you have to think about the context in order to understand how a variable will be interpreted and with a more strictly typed language you don't.

jdrietz wrote: Another way to put this might be to ask whether using PHP as a first language is more likely to result in bad programming habits/styles versus starting with C because C demands stricter attention to detail?
If you consider memory management as a detail, then yes, it would be plainstupid to focus on it... Since it's a detail and not part of the 'main solution'.

You can learn bad programming habits and styles in any language.. And it's in all languages quite easy to do so.. Therefor: learn the logic and algorithms first (this way you can at least solve problems) and afterwards learn the language specific bits...
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

you all ready know my stance if you read teh thread ;) I still stand by it. :)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

jdrietz wrote:If you don't mind, let me take a slightly different approach to my question: Does starting with a language like PHP, which is perhaps more forgiving to the newbie, makes it more difficult to later pick up a language like C because things taken for granted before are now required (i.e. memory management, declaring types, etc.)? Another way to put this might be to ask whether using PHP as a first language is more likely to result in bad programming habits/styles versus starting with C because C demands stricter attention to detail?
If I had tried to learn any other language (with the exception of ColdFusion- but it has its problems, too) than PHP first, I would have quit. That is just my opinion. But knowing PHP, and learning development logic, code progression, basic syntax and code interactions, made it a heck of a lot easier for me to pick up other development languages. Bear in mind that I really have no interest in software development (standalone PC apps, things like that). I develop for the web, so when I say development languages, I am speaking 100% web dvelopment.

Although I have looked at C code and it actually made sense to me. Same with Ruby and Python. It just seems to me that logic lays a pretty good foundation. Syntax follows closely behind.
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

jdrietz wrote: If you don't mind, let me take a slightly different approach to my question: Does starting with a language like PHP, which is perhaps more forgiving to the newbie, makes it more difficult to later pick up a language like C because things taken for granted before are now required (i.e. memory management, declaring types, etc.)? Another way to put this might be to ask whether using PHP as a first language is more likely to result in bad programming habits/styles versus starting with C because C demands stricter attention to detail?
I don't think learning PHP first would handicap you in learning others, provided you try to learn and use another language as soon as you feel slightly comfortable in PHP. The longer you wait, the more crystalized your thought patterns will be along PHP's lines and not along programming lines in general.
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

timvw wrote: When i started i had a large course which focussed on object oriented programming (which used java as a tool), a course with projects where he had to perform forms of text manipulation (using perl as a tool) and creating a simple gui application to track laptimes at a running event (using visual basic)... But in essence they were all focussed on logic and algorithms and not on syntax...
Wow that's sounds like a very cool course. I like the computer science degree programs that tend to change computer languages with every course -- Scheme for this course, PolyJ for that one, C for another one ,etc. As the instructors assume you'll pick up the language as you go along, they focus on teaching the concepts/techniques, etc that the language helps to expose and not the language itself. Sounds like your course combined all that into a single course.... wow...
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

If you are new to a programming language and have never programmed before, it's going to be difficult no matter what. If you know what you're doing in a different programming langauge and start another, it's a piece of cake.

I learnt Visual Basic first at college, but already knew a bit of HTML/CSS/PHP. I got into PHP properly after I'd fully understood Visual Basic.

As soon as the programming logic is learnt in one language, it carries across, the only things you need to learn are syntax and function names.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

jayshields wrote:If you are new to a programming language and have never programmed before, it's going to be difficult no matter what. If you know what you're doing in a different programming langauge and start another, it's a piece of cake.

I learnt Visual Basic first at college, but already knew a bit of HTML/CSS/PHP. I got into PHP properly after I'd fully understood Visual Basic.

As soon as the programming logic is learnt in one language, it carries across, the only things you need to learn are syntax and function names.
That's partly true, but there are more significant differences with some languages - take a look at lisp ;)

It's true that learning to think correctly and understand logic is HUGE part of programming but there's more than just syntax and function names that vary across languages. There are some fundamental differences between certain languages.
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

Plain and simple, it works like this...

If you learn a low level language like C/C++ and later make the transition into an interpreted environment like PHP or even compiled like Java or C# you will have much easier time, whereas visa versa is not the case...

Any environment which hides details from you, makes it easier to learn, but more difficult to move closer to the machine...

Basically if you really wanted to know how computers worked, you'd do something like:

1) Assembler/Machine
2) C/C++
3) Java/C#
4) PHP/Python

However, you have already made it clear you are not interested in making desktop applications or writting device drivers or master PC internals, etc...

The problem is, you want your cake and to eat it too...

There is no one language that will allow you that, as timvw has said every language serves its purpose...

You can use PHP and learn good programming practice, but you'd need to start off learning principles from square one...and I don't htink I've ever seen an article or book that does this, as everyone I've read or loked at jump right into specifics right away, like programming shopping carts...

That kind of skill will not transfer over to C++ very well

So in short, really you can learn any language and follow good programming practice(dilligence and discipline)...but some languages force better structure on you, like Pascal or Java...

Reading your posts, I can assume you will likely never need the knowledge of a low level programming language, so you can probably rule out C/C++ although IMHO every little bit of knowledge you gain only makes you a better developer...

If you don't want to learn low level programming, you can scrap C/C++...if you want to learn solid programming principles...and need that skill to transcend into other languages, PHP won't cut the mustard...so it's likely Java is your best choice...as it's a *general* programming language like C/C++ but hides many details from you...making the learning curve lesser than C/C++

PHP is a web centric programming language and relies heavily on HTML for interface...therefore skills learned here will not make learning Java later on easier...but learning Java first and later making the transition to PHP would be easier, as PHP hides many details of web development from you...

So to recap...if you are impatient to get going...start with PHP as you can quickly get things up and running, which is important when starting...to keep your interest peaked...within a few months you'd be a professional developer (as in you could do it as a profession) java on the other hand will likely take quite a bit longer as it's general programming language giving you more flexibility than PHP but with flexibility comes a greater learning curve...

Cheers :)
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

jdrietz wrote:Basically, as I said, my goals are to learn good programming habits (I am familiar with "spaghetti code" even in my short time playing around with PHP) and gain an understanding of programming that I can apply to learning other languages in the future (including OO). Secondly, if possible, I want to learn something that I can use for "real-world stuff" like overhauling my blog, building some simple web applications (maybe an RSS feed aggregator), etc. Eventually, I would like to gain the skills needed to do enterprise-size projects.
You give two sets of requirements that pretty well sum up the tension between Java and PHP.

First you want to learn good programming habits, understanding you can apply to learning other languages, enterprise-size projects -- that sounds like Java would be a good fit.

Second you want to do some "real-world stuff" like overhauling my blog, building some simple web applications -- that sound like PHP would be a good fit.

The problem with PHP is that is applies little structure on you so you have to be self disciplined. The problem with Java is that it applies a lot stucture on you so there is a steep learning curve.

Those two languages also have a different outlook on tool use: Java genreally requiring that you learn a tool suite to be productive, whereas PHP tends more toward the "your favorite text editor" and a web browser style.

Learning Java first might make you a more disciplined PHP programmer; learning PHP first might make you a less uptight Java programmer. ;)
(#10850)
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

If starting from scratch, and outside an academic course - go with whatever option suits your immediate needs. At the very least you'll get a good feel for programming, which is the big step when learning. For more advanced study, I'd recommend Java. Yes, the learning curve is steeper than PHP (but, you'll have basic PHP at this stage), but Java is a powerful language that teaches OO well and encourages good practice. Mix and match - once you learn programming (logic/practice/algoriothms/etc.) switching languages is a far more simple exercise. For example, I know PHP developers who've never learned Java but who can still "get the gist" of a Java code snippet. I'd guess a lot of us experienced programmers have touched bases with several. Me, I've worked in C++, Perl, PHP and Java. PHP is my current main language - but I'm also playing around with Ruby which is very fun.
alvinphp
Forum Contributor
Posts: 380
Joined: Wed Sep 21, 2005 11:47 am

Post by alvinphp »

I would say go with any language you want, but do not do it half a$$ed or you will go nowhere.
jdrietz
Forum Newbie
Posts: 6
Joined: Sat May 20, 2006 5:12 pm

Post by jdrietz »

I would say alvinphp's reply is probably the best advice! ;-)

Thanks for all of the advice!
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

And I would say...that should stand for anything you do in life, otherwise what is the point???

When I eat...I put all my energy into...when I sleep...I try...actually I suck at sleeping...so lets skip to the next one...

When I breathe...I breathe like it's my last breath (sp.)

When I read...I read as though every letter my eyes encounter is the last letter I will ever see...

When I hmmmmmmmm....I'm no good a person to person relationships...so I can't say I put much effort into people pleasing...women are sooo demanding...and I'm very selfish...I need *my* time to do my things and it makes me incredibly irrate if anything disturbs that... :?

I can't stand phone calls when i'm on the computer...or having to feed my cat or dog...

I really get <span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span> off if telemareters call right in the middle of some bug I'm struggling with (I pitty those poor girls that get me on a middle of the afternoon Wednesday) :P

Ok...so i'm not perfect...and clearly don't do *everything* to the best of my abilities...

But I've certainly taken this thread off topic...haven't I :P

Cheers :)
Grim...
DevNet Resident
Posts: 1445
Joined: Tue May 18, 2004 5:32 am
Location: London, UK

Post by Grim... »

I would recommend not choosing PHP.

Yes, PHP is easy to learn and simple to use, and that's it's problem - it lets you get away with murder.
PHP is so God-awful at encouraging good programming practises that you start falling into bad, lazy habits.

Perl is a good starting language, is quite simular(ish) to PHP and is far more strict (and, in the UK at least, Perl programmers earn more cash).
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

PHP was my first language. It was hard for me to pick up, as I just read online and did trial & error. After dabbling in it for about 2 years, I can say that it was a good choice for me.

The reasons I think it was a good choice is because I only needed to do server side programming. At the time I didn't know what that meant, but I saw cool websites that had the .php extension so I decided that's what I wanted to learn. I had no interest in client side programming; as you say you don't.

Learning PHP, you can do a lot of things in a lot of wrong ways. That would perhaps be the biggest downfall to going with PHP with your first language. In terms of performance, you can't go wrong with PHP. It's insanely fast and efficient.

However, I do not know any other languages to speak of the pros and cons of each. However if you do decide to go with PHP as your first language; make sure of the following:

Get your facts straight. Read or learn from good sources. You don't want to learn bad practices.
Code with the propper settings to make your code as portable as possible
- register_globals OFF
- short_tags OFF
- magic quotes OFF
Expect a lot of headaches and confusing times.

Along the way you'll discover that you learn a lot more about the server than you expected to learn. And that in turn, I believe, can help suit you for learning a second language. Perhaps a more strict language like Java.

It's also come to my attention that people think PHP (mysql too) is a toy for web developers. I don't know why people have came to this assumption. Perhaps because it's so popular and (relatively) easy to learn? The bottom line is it's a very powerful and capable language.

Congrats if you do choose PHP. :)
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply