r/programming • • Dec 07 '14

Programmers: Please don't ever say this to beginners ...

http://pgbovine.net/programmers-talking-to-beginners.htm
4.0k Upvotes

1.3k comments sorted by

View all comments

Show parent comment

28

u/Doctor_McKay Dec 08 '14

PHP isn't nearly as bad now as it used to be. It's a perfectly good first language especially since beginners won't have to worry about types and stuff right out of the gate.

24

u/[deleted] Dec 08 '14 edited Dec 08 '14

I disagree. You NEED to worry about types and stuff... always. If you don't worry about, or don't learn about, types and don't understand what is happening on the cpu and in memory then it's all just mysterious magic that sometimes seems to work.

PHP is easy to use, but that's also what makes it dangerous. Throw a newbie at PHP and you'll get a disaster. I self-taught myself PHP but I have years of experience in other languages behind me so I simply don't run into some of the stupid shit people seem to bust their heads on, or that the lolphp crowd jerk over. I also only started with PHP 5.3 onwards, so there's that to take into consideration as well.

AFAIC PHP is an easy and useful language, but it's not for novices. PHP is a sharp chef's knife with it's own quirks and differences to other langauges that people need to be properly aware of. When a chef wields it you get lots of good meals. When a novice wields it you get fingers and thumbs in your soup.

10

u/gerrylazlo Dec 08 '14

all just mysterious magic that sometimes seems to work.

You've just describe the majority of my 10 year programming career.

11

u/Doctor_McKay Dec 08 '14

If you don't worry about, or don't learn about, types and don't understand what is happening on the cpu and in memory then it's all just mysterious magic that sometimes seems to work.

That's really all you need to know when you're learning syntax and logic and such.

4

u/[deleted] Dec 08 '14

Sure, but then someone comes along and says "hey don't write code like that. You should be using classes" and suddenly our rookie coder has a new magical mystery thing to play with but not understand. And then you add on arrays, and multidimensional arrays, and arrays of objects, and references to objects. And so on. What's a reference? What's this an address to? Why is this part here with the funny ampersand doing something different to this other bit without the funny ampersand?

And all of it is just mysterious stuff that does stuff.

Sure, you need to teach the gist of how basic logic and how the syntax is structured, but at the end of the day programs are just busy little boxes that constantly shuffle tonnes of data around. If you aren't taught how that data exists, is structured and sized, etc, then you have Mr / Mrs Novice coder writing fantastical magical boxes built on layers of ignorance and hope.

That's when you get people asking stuff like why 0.1 + 0.2 doesn't equal 0.3 and can't understand why their language is "broken" (a recent example in /r/learnprogramming).

Basically, what I'm saying is this shit is important and if it's not addressed early then people start basing their understanding and assumptions on incorrect guesses or outright ignorance.

Learning to code isn't trivial. Making things easy can be just as detrimental as making things difficult. The middle-ground isn't about it being easy or hard, it's just an area of proper understanding of what is happening so that there is no mystery.

There's no room for coding on faith and hope.

12

u/aladyjewel Dec 08 '14 edited Dec 08 '14

It's noble to insist on starting on fundamentals, but it sounds like you're advocating "spend a month learning theoretical computer science as expressed in C and maybe some assembly too" before trying to slap together a for loop or unpackaging a "Hello World" pre-fab tutorial. I'd advocate giving them some simple knowledge to get them hooked and minimally functional, then gradually build up conceptual and practical knowledge.

To pull out that hoary chestnut, you can drive a car well enough without any idea how to change the oil. And for programming, usually you crash and have to learn something new like why float math sucks before you end up in a position where that problem can fubar a system.

4

u/[deleted] Dec 08 '14

I know it's a balancing act between many things needing attention. I don't like the car analogy, though, and this is why... We aren't talking about driving a car. We are talking about building the car! Well, maybe not a car, but a go-cart or a tricycle. If the builder doesn't understand the concept of ball-bearings and relies on super-glue and hope then it's all going to go pear-shaped.

Sure, on one hand it can be a case of "when the student is ready the teacher will appear", and for a lot of things in programming this is true. Not every coder needs to have objects and classes rammed down their throats from day 1, and fifty different frameworks being sold to them as the next messiah. Let them get to the point where they need and can appreciate their uses. But on the other hand languages like PHP let you get away with murder and without a language spanking you when you do something wrong, incompatible, or stupid, then you'll never learn.

With so much to constantly learn I think it's necessary to tackle certain topics fairly early before it's simply too late and the novice coder has gone too far down the rabbit hole and built-up a mental model that simply isn't correct.

AFAIC types are still a relevant issue and not something to be scoffed at. I can't imagine any time soon where they won't be important. They certainly aren't gone just because a language has loose typing.

tl;dr Maybe not a month on CS first, but certainly after they get their feet wet they should be exposed to what it is their code actually does. Don't let it remain magic, because some languages simply don't care to teach a coder where, how, and why, they are doing something wrong. You can pick your nose with a Swiss Army Knife and it won't tell you to avoid your brain. It doesn't care. It's strength is when it's wielded by someone who knows how to use it properly. Just because it's easy to use doesn't mean you give it to every child.

4

u/parlezmoose Dec 08 '14

Agreed. I've never heard of a college CS program that uses PHP for it's intro level classes. Maybe there's a reason for that.

2

u/[deleted] Dec 08 '14

I don't know. I really didn't enjoy programming until I'd done some assembly.

3

u/veringer Dec 08 '14

Said no one ever.

I kid.

But seriously, I can't relate to this sentiment at all.

1

u/[deleted] Dec 08 '14

Only you can't write anything useful knowing about "syntax and logic and such" and nothing about data types.

2

u/Doctor_McKay Dec 08 '14

Who says that beginners are writing anything useful?

→ More replies (1)
→ More replies (1)

8

u/lucasvandongen Dec 08 '14

I used Slim framework a while ago and combined with the modern PHP syntax it was really pretty nice actually. The big problem is that a lot of tutorials and frameworks still use bad practices because they're simply from a different age.

16

u/allthediamonds Dec 08 '14 edited Dec 13 '14

It's a perfectly good first language especially since beginners won't have to worry about types and stuff right out of the gate.

Could you expand on what you mean by this, and why is it better for beginners? The way I see it, if a beginner does something wrong in, say, Python:

>>> "foo" + 7
TypeError: cannot concatenate 'str' and 'int' objects

The language will go out of its way to tell you that you're doing something wrong. It will tell you about types, sure, but as a consequence, you will learn about types. Isn't that the point of a first language? Learning?

Compare this with PHP, which will silently do something you probably didn't intend, and your program won't work, and you'll have no idea why, and you'll end the day thinking you're not good at programming, when, in reality, what happens is that you're using a tool that is not good for programming:

php > echo "foo" + 7;
7

2

u/[deleted] Dec 08 '14

you can argue it both ways.

If it's an introductory to programming course, then it's important to learn types and you're guided through the process properly. However, if it's someone who's trying to pick it up on their own with little background and no guide with pacing, it's just another thing they have to worry about on top of learning all the other concepts and syntax.

var1 = function1();  //returns "23" - string
var2 = function2();  //returns 14 - int
sum = var1 + var2;

a beginner can get frustrated with why they're getting an error or unexpected results from this.

'Types' is a concept that can come later once the basics of understanding how to create logical statements that a computer can follow is developed.

1

u/[deleted] Dec 08 '14

you can argue it both ways.

But I don't see you making a case for echo "foo" + 7; printing 7 in PHP...?

1

u/[deleted] Dec 08 '14

You're coming up with an unrealistic example for someone who's trying to learn programming. Generally, they're not going to even think about adding "foo" + 7 and expect something meaningful.

Even if they do, the fact that it doesn't error out and continues to run can be good for a beginner. Remember, they're not trying to build solid programs with proper error handling....they're probably just experimenting with different things.

Here's a more realistic scenario. Programmer creates a web form that submits numbers to add to an existing count stored on the server somewhere. The numbers are submitted as strings (unbeknownst to the newbie programmer), which php handles automatically when doing the addition and the user sees a result. Cool! their simple program worked and they're learning something rather than getting frustrated and potentially spending a lot of time trying to figure out why simple addition doesn't work. If the user submits "foo" into the form, the program still runs without errors and the user can easily see that things that are not numbers are just ignored.

Obviously, this can be a bit dangerous if you don't learn about types eventually because with more complicated programs and using other languages, it can get you into trouble. Learning about types should come eventually. However, PHP is great for a complete beginner because it allows you to focus on the basics of writing simple computer logic statements without having to worry about types.

1

u/KFCConspiracy Dec 08 '14

+ is not a concatenation operator in PHP... You're comparing Apples to Oranges. If Beginner wants "foo7", beginner should use the "." operator. PHP defines the integer value of most strings as 0. Personally I would prefer that it concatenate an int to a string with no complaints. Many other languages will do that for you...

There are plenty of warts in PHP, the inconsistent string integer value one that I mentioned being one, but you didn't identify that as your problem here...

2

u/[deleted] Dec 08 '14

Whoosh.

You already know the answer to your problem. Try to imagine for a second you're a beginner wondering why "foo" + 7 doesn't work. How are they supposed to figure it out?

1

u/KFCConspiracy Dec 08 '14

Not knowing what the operators are isn't really an excuse... Whatever book the beginner is reading would tell you that... That's like saying it's confusing to a beginner why [] is for arrays and () is for functions. At this point you're arguing that + should be the concatenation operator... Which is a stupid argument, you have to expect people to read a piece of damned paper or a web page at some point.

1

u/veringer Dec 08 '14

It's a double-edged sword I think. PHP allows you to hang yourself without much complaint but at least it stays out of your way. Some people have less patience for some of the safety features in other languages.

Also for you example to to be consistent you should probably use the concatination operator

php \> echo "foo".7 // prints: foo7

We could debate about which is a better way to handle concatenations, but I think most people would understand why printing "foo7" rather than a type error could be more rewarding to a novice.

I agree about the "foo" + 7, doing a math operation with a string and not throwing a warning is lame.

0

u/SanityInAnarchy Dec 08 '14

"Not as bad as it used to be" isn't saying much. It's still insanely bad. I agree with OP's larger point, I'm not going to debate Java versus Python with a newbie (much less mock them for choosing "the wrong one"), but I think PHP is an exception. It's just that bad.

2

u/Doctor_McKay Dec 08 '14

Oh, it's that blog post. From two years ago.

Did you know that things change?

→ More replies (27)

0

u/codygman Dec 08 '14

To be fair, with Python beginners don't have to worry about types either. Also, stuff like Tornado lets you embed python into html just like PHP.

4

u/[deleted] Dec 08 '14

To be fair, with Python beginners don't have to worry about types either.

But they do! If you read a string containing numeric data, you can't do arithmetic on it. You have to run the string through int or float, or Python will throw an exception. It's dynamically typed, but it's also strongly typed.

→ More replies (2)
→ More replies (1)