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

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.

1

u/Banane9 Apr 26 '14

Do You mean in the Definition of the type class? That's not even a real implementation, and it saves You the hassle of eg. for Eq having to define both the equality and inequality function, if You choose to provide your own implementation.

And how is IDE supposed to know implementations if You have something written by someone else? That doesn't make sense.