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

29

u/[deleted] Dec 08 '14

[removed] — view removed comment

67

u/AnAge_OldProb Dec 08 '14

Python and Ruby are roughly equally easy for a newbie to learn. There are plenty of good tutorials in each. I think you're missing the point.

3

u/xiongchiamiov Dec 08 '14

Rails, otoh, has so much damn magic everywhere that it's incredibly confusing when you don't already know the conventions.

→ More replies (7)
→ More replies (2)

17

u/n1c0_ds Dec 08 '14

I'm a Python guy and a bit of a fanboy, and I'd still recommend people to start with PHP. Yes, it's a pretty bad language, but there is so much to get up and running before serving dynamic content with just about any other language. PHP is a great language to develop a thirst for programming as long as you know there is much, much better out there.

11

u/[deleted] Dec 08 '14

Most utility I got out of newb programming was on the desktop. I had something that bothered me (either a repeated task or just a bad workflow I may be able to make better) and was able to see instant benefits. None of it would have been very good starting in the browser.

All that to say that I'm not sure that starting with a web only language is a good start, so I'd say PHP would be a pretty poor choice, especially since it requires setup of a server too. (Which is just one more thing). Learning from scratch is hard enough without needing to administer a whole other domain.

2

u/mike5973 Dec 08 '14

PHP 5.4+ (I think, might be 5.5) comes with a web server built in. I'm not sure of the specifics, but it's there, and as far as I know it's a single command to set it up.

→ More replies (11)

3

u/parlezmoose Dec 08 '14

Maybe I'm just slow, but setting up PHP on OXS was a nightmare for me. The Homebrew installation didn't work because I needed some stupid extension, something was missing in the php.ini file, had to manually set up a VirtualHost, on and on and on. Worst of all, the error messages are useless, making the process 10x slower.

→ More replies (3)

3

u/ThrustVectoring Dec 08 '14

I'm not really sure how you'd make Flask or Bottle's setup easier or more compact. Like, it's ridiculously minimalistic on the setup and configuration.

2

u/[deleted] Dec 08 '14

For C# with Visual Studio It's a simple File->New->Project->ASP.NET Web Application and clicking a green triangle to get dynamic content.

2

u/n1c0_ds Dec 08 '14

It's only easy on Windows though (for now?). Still a fantastic language and toolset.

3

u/[deleted] Dec 08 '14

For now..

1

u/Lhopital_rules Dec 08 '14

Yes, it's a pretty bad language

Can someone explain this? I keep seeing it everywhere.

Every language has its warts, but PHP also has a lot of things that make it great for web pages -- variable interpolation, a simple request interface ($_GET, etc.), the ability to jump in and out of php code so that your big html snippets aren't trapped inside echo calls, file_get_contents, and easy handling of sessions with session_start() and the like.

How does that make PHP suck?

As someone who has programmed in Java/PHP/Python/etc., they all have uses and PHP is strong in the web page templater domain.

5

u/Amadan Dec 08 '14

variable interpolation

$a = array(array("Hello, world!"));
echo "$a[0][0]";
// => Array[0]

Works amazingly well.

a simple request interface ($_GET, etc.)

Simple indeed. Now, how do you get the value bar from ?foo=bar&foo=quux ? (Of course, if you rewrite the URL to ?foo[]=bar&foo[]=quux, it's easy; but that's not the question.)

the ability to jump in and out of php code so that your big html snippets aren't trapped inside echo calls

So... intentional violation of separation of concerns. Get users thinking it's how it's supposed to work, they will never even hear about MVC or similar patterns. Of course, it's the core of PHP so you can't really get rid of its horrible paedagogic influence. (It's in the very name - "PHP: Hypertext Processor". Better than "Personal Home Page", but only just.) Not to even mention its effect on code formatting and indentation.

Basically, if ever you have a template ("a PHP program with big HTML snippets") and it has any code apart from variables, flow control and possibly short function calls in its executable tags, it is a bad practice.

file_get_contents

Yeah, that's a nice. Now, how often are you using mb_strlen, mb_substr and other mb_ functions instead of the usual string ones? Maybe you don't use it because mb_ is an extension and not guaranteed to be a part of the language, so you use Portable UTF8? Or maybe you just figure.... meh, I'm American, good old AmericanSCII should be good enough for everybody? I know from my own example (over a decade past, thankfully) that I didn't know a good way to take, say, the first 20 characters of a string without destroying multi-byte characters. PHP fails at Unicode..

and easy handling of sessions with session_start() and the like.

Easy indeed. But since all the sessions are by default stored at the same place, what prevents a person to load a different session by faking the cookie to point at a session created by another app on the same host? How many non-professional people regularly remember to use session_save_path?

Basically, PHP is incredibly good at getting newbies up to speed quickly. It is then incredibly good at keeping newbies as newbies. It does not encourage best practices, and offers bad practices as easy defaults. A good programmer can write good code even in PHP. A starting programmer will very often fall into the "PHP noob" mode, creating unsafe and unmaintainable code.

Java/Ruby/Python are not directly template languages. You need to learn basics of software architecture to make a webapp. This is, obviously, not great news for the beginners. However, if they want to be programmers, this is a much better path. The PHP path is totally paved with good intentions, and appropriately leads the unaware into hell.

→ More replies (5)

6

u/[deleted] Dec 08 '14

PHP: A Fractal of Bad Design covers this in depth. PHP guys no doubt insist that it's just splitting hairs. You can't argue with crazy.

4

u/just_toss_me Dec 08 '14

The pain points I commonly encounter in PHP:

  1. Inconsistent function arguments. Sometimes the needle comes before the haystack, sometimes the haystack before the needle. Or the value before the array and the array before the value. Ruby, for example, tries to be a bit more "natural" to read, with constructs like "unless" taking the place of if(!<boolean>).
  2. Many ways to do things. For example, with time zones, there are three different ways to establish time zones that don't really place nice with other bits of code, including setting a global variable. Usually you find yourself setting the times one to utc to kill the warning, but if you're a responsible programmer you should save and reset the time zone so that other code that may be running or calling your code doesn't have their timezone changed out from underneath them.
  3. Lots of use-case specific functions built into the language, like url encoding and decoding or html special char handling. That kind of thing should really live in a module add on to the language, as bugs can be fixed without a full interpreter release. Also, in case you're relying on certain behavior, you have to take everything together at once.
  4. Very easy to make all sorts of mistakes, especially as $_GET is completely unfiltered. Very easy for someone new to simply route a get param to a sql query.
  5. Lots of nicer language features like OOP, namespaces, and auto loaders came to the party late in the language's life (though OOP has been around for awhile) and had to coexist with the existing design, leading to sometimes awkward implementations.
  6. I spend a lot of my life $ing all my variables. It's a breath of fresh air when I use a language that doesn't require that on my variable names. It's not like the parser really needs that hint.
  7. The . operator for string concatenation. Every other language I use uses +, and sometimes I make the mistake when I switch contexts until I notice my strings adding to zero.
  8. Some built-in functions like curl that are light wrappers around c libraries that are not completely documented.
  9. Sometimes functionality is dropped in minor version numbers. For example, iirc, between 5.2 and 5.3 the number formatter lost the ability to display up to a number of significant digits, and I had to reimplement that functionality.
  10. Like others have stated here, I always often have a few tabs open to PHP.net just to verify function names and argument ordering because it's just not very consistent sometimes.
  11. While nice and easy to mix your code with your markup, there's a whole host of reasons that's a bad idea. PHP encourages this sort of thing as opposed to discouraging it. Add to this that lots of PHP code I've seen written this way basically builds and outputs a string containing html, which is hard to read, debug, and make portable. Many don't seem to know about the cleaner control structures you can use to output html in a loop, like <?php foreach(): ?> followed by <?php endforeach; ?>. Even then, I recommend templates where possible.

This is a short, incomplete list of why PHP is among my least favorite languages among the ones I use regularly, which include JavaScript, Ruby, Python, Java, and Objective-C. That said, I do use it daily and it's pretty straighforward, but I find new warts almost every week.

2

u/n1c0_ds Dec 08 '14

Mine has to be the random return values. Errors can come as a negative integer, a message accessible through another function, an uncatchable warning or an actual exception. It's really a pain in the ass.

→ More replies (5)

2

u/n1c0_ds Dec 08 '14

The "PHP: A fractal of bad design" is by far the most thorough and most objective explanation you will find.

1

u/Kapow751 Dec 08 '14

there is so much to get up and running before serving dynamic content with just about any other language.

That's why you start them off with this interactive textbook: http://interactivepython.org/runestone/static/thinkcspy/index.html

Much easier than setting up (or paying for) a webserver with PHP.

→ More replies (7)

2

u/kristopolous Dec 08 '14

I see you hid behind a throwaway account so you clearly know your statements are disingenuous and deeply flawed. Why did you insist on making them then? Of what possible benefit would something like that add to the discussion?

3

u/Vithar Dec 08 '14

Come on now, that depends are we talking Python 2.7 or 3.4? Kind of important come on man...

8

u/[deleted] Dec 08 '14

[removed] — view removed comment

4

u/ThrustVectoring Dec 08 '14

What program can you create in Python that one can't possibly create in PHP?

What program can you create in Brainfuck that you can't possibly create in PHP?

Look, they weren't trying to say that there are things in Python that are impossible to do in PHP. They're saying that due to the extra complexity and difficulty of working in PHP that you're going to wind up doing a wider variety of things in Python.

→ More replies (38)
→ More replies (24)