Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

From my own experience, developers, particularly inexperienced developers, when learning something new have an insatiable need to implement their new found knowledge .. no matter if it's a good fit or not for the problem at hand (myself included .. I remember abusing the hell out of recursion for example).

One of the worst examples I've seen is the functional programming paradigm being crowbarred out of PHP .. why.



One of the worst examples I've seen is the functional programming paradigm being crowbarred out of PHP .. why.

Most likely related to the Innter-platform effect: ...the tendency of software architects to create a system so customizable as to become a replica, and often a poor replica, of the software development platform they are using.

http://en.wikipedia.org/wiki/Inner-platform_effect

One of the classic PHP examples being the Smarty templating system:

Smarty has been criticized for replicating features that PHP does natively very well, which leads to inefficiency:

http://en.wikipedia.org/wiki/Smarty


Hey bill - looks like you've been hellbanned. Something that you said on http://news.ycombinator.com/item?id=4213223 ticked someone off. Maybe talk to info@ycombinator.com and get it sorted out.

PHP still sucks though ;)


Wow, I've seen much worse snark on HN get all the upvotes.


Yep. Evaporation in action... :(


The implementation of higher-order functions in PHP has saved me hundreds if not thousands of lines of code, and that's only in the last six months.

It's not perfect, but it's better than what we had before.


If you're talking about PHP's anonymous functions then yes I agree they have made life a lot easier. I was talking more about projects like Swiftmailer for instance, example:

  // Create a message
  $message = Swift_Message::newInstance('Wonderful Subject')
  ->setFrom(array('john@doe.com' => 'John Doe'))
  ->setTo(array('receiver@domain.org', 'other@domain.org' => 'A name'))
  ->setBody('Here is the message itself')
  ;


That's called a 'fluent interface.'

It's useful in some instances, and is a bit different than currying because PHP doesn't really support proper currying.


Ah, I thought they where going for functional as that's the response I got when talking to one of their developers about it.


That's probably because their developers didn't know what they were talking about.


I suspect xd doesn't either.


Nice. Are you trying to tell me that that example doesn't appear to try and avoid state?


That example is full of state. There's nothing to prevent you from calling any of those setX methods at a later point in time and changing the object's state. That interface very well could avoid state, but Swiftmailer doesn't seem to be implemented in that way. [1]

The stateless way would be to return an entirely new Swift_Message instance with each setX method. In languages that aren't built with immutability in mind, like PHP and Java, you end up instantiating and throwing away a lot of objects. Sometimes it doesn't matter, but when it does you use a mutable Builder to create the immutable instances.

[1] http://swiftmailer.org/docs/messages.html


That example is full of state.

That's why I said it appears to try and avoid state. Either way, as far as I'm concerned it's an horrific way to write code in an imperative language such as PHP.


I beg to disagree. It's a variation of the builder pattern and I find it quite useful, thank you.


Not to me.

setX is reminicent of Java to me, and of small talk attribute setters/getters before it.

Both of those languages elevate state to the point of godhood.


It's not about the setters/getters directly, it's the way they are being called by returning references to the parent object in each method call.


Right, and that's an insanely common idiom in Java, where state is A-number-one best friend.


Ah, I see. I'm no Java developer, sorry.


This looks exactly like Smalltalk's cascading; just allows you to not repeat $message loads of times. To me it's a useful feature which I often would like when working with lots of Java libraries.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: