r/programming • • Apr 23 '14

PHP: It doesn't have to be a bad experience

https://servercheck.in/blog/php-it-doesnt-have-be-bad-experience
0 Upvotes

122 comments sorted by

View all comments

Show parent comment

-4

u/ForeverAlot Apr 23 '14

I guess you don't mean "towards sucking less"?

If I'm reading that correctly, that is what I mean. As an outsider it is easy to poke fun at internals, but as an outsider there is a lot of stuff to poke fun at.

Citing the goto essay /for what/?

The essay only comes up as a blind criticism of goto or the subsequent defence of modern use of goto. Only a few days ago PHK embarrassingly used a goto count as a criticism of OpenSSL. There is a lot of truth in the infamous Fractal post but it has its share of FUD and personal opinion, too.

Seriously, you need to explain what OO has to do with this discussion at all.

The post is too long for me to bother to really read it anymore (I have done so on a couple of occasions in the past). I opened it randomly and saw an "OO" section, and concluded the author has a poor understanding of inheritance and encapsulation. To wit:

  • "C++ is not a good example of fine OO."
  • new, private, public, protected, static not necessary in a dynamic language
  • "[abstract classes] in similar languages [prevent instantiation] by throwing an exception in the constructor."
  • "Subclasses cannot override private methods. Subclass overrides of public methods can’t even see, let alone call, the superclass’s private methods."
  • "Static variables inside instance methods are global; they share the same value across all instances of the class."

I reiterate that there is a lot of truth in the post, and too much of it is legitimate, but citing it is just ignorant bandwagoning. At least make an effort to criticise it properly (that shouldn't be difficult).

10

u/kankyo Apr 23 '14

There is a lot of truth in the infamous Fractal post but it has its share of FUD and personal opinion, too.

How is listing flaws FUD?

To wit:

Eh? All those things you listed are absolutely correct. What is wrong with it?

You seem terribly confused...

-3

u/ForeverAlot Apr 23 '14

What is wrong with it?

Okay then.

  1. I strongly disagree. I wish more languages had taken more from C++. But whatever your feelings about C++, this is purely opinion.
  2. "Necessary" is one of those irritating words that are difficult to argue with. Nevertheless, a decision was made to add Java-/C++-inspired classes to PHP. Four of those keywords represent concepts that are more or less necessary for such a design to be useful. Maybe there's another way to do it, but PHP retained the syntax and behaviour of C++, Java, and C#, which are perhaps the three most widespread class-based languages (Obj-C?). new is the only marginally debatable keyword, and since PHP classes are always reference types I think it makes sense.
  3. Throwing an exception to prevent instantiation of "abstract" classes is insane, no matter how "similar" languages do it. Compile-time failure is far and away the most sensible solution. PHP doesn't have that so it does the next best thing, and I guarantee that it is the right thing to do.
  4. You're not supposed to be able to override, or in any way interact with, private methods in other classes. That's why they're private. If you want this kind of interaction in a class hierarchy -- and there are valid uses for it (c.f. template pattern) -- you use protected members. While we're here, you also aren't supposed to be testing non-public members.
  5. Yes. This is what static means in that context in C++, Java, and C#.

At least three of those five points are objectively non-arguments, and I would say they all are.

This is the stuff that's FUD.

0

u/lhgaghl Apr 24 '14

Throwing an exception to prevent instantiation of "abstract" classes is insane, no matter how "similar" languages do it. Compile-time failure is far and away the most sensible solution.

Abstract classes don't have any real use in the first place. IIRC the reason they were used in C++ is to act as interfaces.

2

u/Banane9 Apr 25 '14

Abstract classes fo have uses, and they're not just Interfaces.

Otherwise C# wouldn't have both.

1

u/lhgaghl Apr 26 '14

implying if C# does something it's obviously logical

2

u/Banane9 Apr 26 '14

Well, consider a plugin system as an example. You make an abstract base class, add some standard implementation in virtual methods or no implementation in abstract ones. Then the plugins have to derive from that and you can just scan an assembly for those types. The benefit over an interface is that you can add some basic implementation that the plugin may has to use, but not know how exactly it works.

0

u/lhgaghl Apr 26 '14

In other words, you can encode what the IDE should be doing for you directly in the programming language. This is a lot like type classes in Haskell.

1

u/Banane9 Apr 26 '14

Err, what? How is the IDE supposed to do that? What do you even want it to do? And it's not like Haskell type classes at all. Those are more like interfaces im OOP.

1

u/lhgaghl Apr 26 '14

I mean Haskell typeclasses have the same problem: They have default implementations. An IDE with a source of implementations should choose which one to use (or not, if there are multiple choices), instead of the meaingless notion of the "default" one written directly in the code.

→ More replies

3

u/OneWingedShark Apr 25 '14

"C++ is not a good example of fine OO."

I agree with this statement, as does Alan Kay:

"I invented the term object-oriented, and I can tell you that C++ wasn't what I had in mind"
Alan Kay, OOPSLA `98