Hacker News new | ask | show | jobs
Show HN: Functors, Applicative Functors and Monads in PHP (github.com)
46 points by widmogrod 4115 days ago
3 comments

Maybe some comments in the examples would help explain what the code is capable of and what it is intended to do. If you're going to do this in PHP then make more PHP examples.
why don't you guys just use functional languages if you need functional features, instead of hacking stuff into languages born with different purposes?
Well if fun factor is not good enough answer, then maybe this will work:

- Using something and understanding it, are two different thing. Through implementing things in a language that I'm familiar with, is easier for me to grasp concept behind it and understand it.

- Create a bridge between foreign concepts. If someone knows only PHP and will grasp FP concept in PHP, then it will be easier for him learn new language.

- Sometimes switching to another language in your daily (commercial) work is not easy as it sounds.

- OOP and FP can do awesome things when used together.

+1

Out of curiosity, just a quick question (disclaimer: it's been a while since I've been doing any PHP - I think it was 5.3)...

Although the language had some OO capabilities, I wouldn't have defined PHP as an OO language but more of a procedural/imperative language.

Has it changed lately? I mean, are there new libraries, frameworks and so that are more OO?

Thanks :)

It's come on leaps and bounds in the past few versions IMO. Partly because of new language features (proper namespaces (enabling easy autoloading), traits etc) and partly because of the community pushing decent standards [0], [1].

It's also worth pointing out that since 5.3 the Laravel framework [2] has been created and in its latest iteration it draws a lot of inspiration from ASP.NET MVC and Rails (the former resonates with me coming from .NET land; though I've not much experience with the latter), making it a great framework for rapid prototyping. Its coding style encourages a lot of good practices and it's become very much the go-to PHP MVC framework, at least for me.

A good resource for reading up on 'modern' PHP is PHP the "Right" Way [3] - there's also a (very recently released) O'Reilly book on Modern PHP [4] written by the creator of a popular micro framework [5] - I've not had chance to read it yet (and I'm sure I'm not its target audience) but I have enough faith in the author to know it'll be a worthwhile resource.

Having said all of this, it is still PHP and you will still be working with some of the old quirks. I've just grown somewhat fond of them :)

  [0]: http://www.php-fig.org/
  [1]: https://getcomposer.org/
  [2]: http://laravel.com/
  [3]: http://www.phptherightway.com/
  [4]: http://shop.oreilly.com/product/0636920033868.do
  [5]: http://www.slimframework.com/
The language itself has been transitioning to OO for a long time, since version 4 actually.

I do remember years ago when I'd take over a PHP project, and it would be procedural. That hasn't happened since around the time CodeIgniter came out.

So not everyone in the PHP community understands good OO practices, but they've been (generally) releasing code organized into objects for a long time.

Definitely PHP community grown a bit in areas of good design like DDD, BDD, SOLID,...

There is a lot of interesting project utilizing this power. The best place to start is this link: https://github.com/ziadoz/awesome-php

not everybody has the luxury to change stack - besides, seeing concepts implemented in a familiar language lowers the bar required to understand them
Very cool.