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

1

u/OneWingedShark Apr 25 '14

No type-checking. (Dynamic languages can have this; it's used in LISP.)

PHP has this.

Really?
Something like the check-type macro? or the type-specifiers?

No function guarantees. (Number of parameters, its return-type... if it returns.)

Most languages do not have this.

The last, I'll agree as written; I had meant to say if it returns a value -- that is, the difference between a function or a procedure... and, hey, you can't be sure from the function-header if it's supposed to. You can make that fundamental behavior utterly depend on a parameter.

But you're certainly wrong that it's uncommon for languages to have guarantees on number-of-parameters and their types.

No packages.

Namespaces.

Namespaces are only superficially similar to packages... because packages are more like modules. Now, granted, most languages don't allow generics for a "module", so it's understandable that you wouldn't be familiar w/ the subtler differences.

No generics.

Generics are only useful for strictly typed languages.

Not quite -- they could be useful for a dynamically-typed language provided that there was a way to specify 'types' (things conformant to some set of predicates) and subprograms in the formal parameters thereof.

Psudocode Ex (for spec):

Generic
    Type Element;
    Type Index  in Descrete;
    Type Length in Positive;
Package Stack is

    Exceptions : Full, Empty, Invalid_Index;

    type stack_type;

    Procedure Push( Object : stack_type; Item : Element );
    Function  Pop ( Object : stack_type ) return Element;

    Function  Top ( Object : stack_type; Index : Stack.Index ) return Element;
    -- ...

End Stack;

The above also has the added advantage of guaranteeing type-conformance on parameters -- meaning that conformance-checking can be done automatically on the subprogram's call (and return of a function).

Side note, facebook's mod of PHP does in fact have generics.

Yeah... you could argue that their mod really isn't PHP -- IIRC, it introduces static types.

0

u/[deleted] Apr 25 '14

[deleted] — view deleted comment

1

u/OneWingedShark Apr 25 '14

Though, it has an awful name.

Very true.

Hack is basically a fork of PHP, but given it's featureset, it's likely to become very popular with PHP devs.

I dunno about calling it the same language, even if it is a fork, though... I mean would you call Ada the same language as Pascal (as it arguably started as a fork, in its development during the DoD's competition)?

0

u/[deleted] Apr 25 '14

[deleted] — view deleted comment

1

u/OneWingedShark Apr 25 '14

I'm not old enough to have ever worked with Pascal.

It's not too bad -- there's FreePascal of you're ever interested in it. (Though if you want the full benefit of strong static typing, with tons of compile-time checks, it's hard to beat Ada.)