6 ms·
Addition of 1 and 1 in PHP
- jordan_clark 14y agoGood one.
- BjoernKW 14y agoHooray for enterprise software 'design patterns'.
- canibanoglu 14y agoHilarious!
- flatline 14y agoThe only flaw I can see is that the string literal '1' should have been declared as a const somewhere, preferably in another unrelated library, and called something like 'UNITY_VALUE'.
- fruchtose 14y agoSee, this is why I'm tired of freelancers and architecture astronauts at companies who just like to make things more complicated. UNITY_VALUE? Seriously? The agile approach would be to contact the customer, ask them what kind of user story they need to interact with the number 1, e.g. "As an admin, I want to interact with the number that is the square root of 1, which is also the product of i^4, and the multiplicative identity." There may be some back and forth on this, since regular users (not just admins) will want to work with the number prescribed above. Then, you need to draw up a quick prototype. We don't need any crap like UNITY_VALUE polluting our beautiful agile code. Instead we'll declare a constant called ONE somewhere. (It doesn't matter where you put it, since we'll probably just Martin Fowler that code anyway in 10 weeks--actually, make that 2.) Then you go back to the customer, show them the prototype. In my opinion, it helps to show them Euler's identity or the multiplicative identity just to assure them it works, in case they doubt it. (They probably will doubt it, since all this agile process stuff looks like automagic to the unenlightened morons we call customers.) Then move on. Done. Bam. No need for this UNITY_VALUE junk. No additional libraries. Agile magic.
- tsahyt 14y agoOn the note of that, there should really be a SimpleNumberFactory.
- pestaa 14y agoYes this is a good joke until you realize there is no other way to get some level of type safety in PHP other than adding a bunch of unnecessary classes.
- lzh-ng 14y agoOh come on, PHP is a dynamically typed language. That's the trade.
- pestaa 14y agoStrong typing and dynamic typing are orthogonal. You can have the former and ignore the latter - see Python - and you can completely forget about both - see PHP.
- deleted 14y ago[deleted]
- raverbashing 14y agoThat's like saying the only way you can get your car to remain buoyant over water is attaching a huge flotation rig to it and even then it won't be as fast as driving on the road
- babuskov 14y agoI know a couple of Java programmers that will find this helpful. Thanks.
- drivingmenuts 14y agoWhat Java really needs is a KitcheSink class. I'm pretty sure there's already one in PHP.
- Joeri 14y agoNo, but it has a bunch of kitchensnk_ functions in the kitchensnk extension.
- pavel_lishin 14y agoThose have been deprecated, you really need to be using the real_ksink functions. Be careful, though, the argument order swapped.
- pixl97 14y agoIs it real_ksink2cabinet, or real_ksinktocabinet, or real_ksink_to_cabinet? Why is it so hard to put the dishes up? http://phpsadness.com/sad/48 http://phpsadness.com/sad/48
- eclipticplane 14y agohttp://www-archive.mozilla.org/docs/web-developer/samples/kitchensink.xml http://www-archive.mozilla.org/docs/web-developer/samples/ki... used to be available in Mozilla as "about:kitchensink"
- cubsink 14y agoThis is brilliant, I will use it on all my php sites.
- nicholaides 14y agoI'm not familiar with the PHP ecosystem. Is the author making fun something other than obvious over-engineering? Does he or she feel like that's a problem in the PHP ecosystem? I'm criticizing, because it's funny. I'm just trying to figure out if theres some wisdom being conveyed that I'm missing.
- nikic 14y agoI think he is mocking the general pattern of over-engineering and PHP just happens to be the language he wrote this in. At least PHP is not a language known for massive over-engineering. Usually people associate the exact contrary with PHP. But there is indeed a recent trend towards better object oriented designs in PHP and with it comes also more over-engineered code. But I have yet to see any Java-style absurdity. Maybe we'll still get to that ;)
- jablan 14y agoDon't you think that, when it comes to OOP features, PHP recklessly introduced lots of Javaisms which lose lot of sense when applied to a dynamically typed language? I believe the author had exactly that in mind.
- jonascopenhagen 14y ago> I have yet to see any Java-style absurdity. Then you probably haven't tried Zend Framework ;)
- Mahn 14y agoReminds me of something I wrote a few months ago on how to detect negative numbers: http://stackoverflow.com/a/11910993/1329367 http://stackoverflow.com/a/11910993/1329367 but obviously the one above has much more value add and follows better design patterns.
- UnoriginalGuy 14y agoYou have to have a sick mind to come up with something like that, I salute you sir.
- solistice 14y agocringe ... a<0?sth:sthelse; phew...
- zerovox 14y agoThe addition operator takes a collection of numbers, and add the first two? Given the lack of documentation, I find this extremely misleading and I couldn't recommend this library.
- phaikawl 14y agoseriously?
- juskrey 14y agoAn example is pretty good, but I am not sure about scalability and load balancers.
- Mahn 14y agoI think this has potential to scale, but you'd probably need to throw in more servers if you plan to handle more than few hundreds of additions per second.
- sneak 14y agoOh, did someone port Twisted to PHP?
- merinid 14y agoThis is so funny. The author's description is great on github, really fooling you at times. Even if this isn't intended as a joke, the dedication to doing something fun to prove a point got me thinking about over engineering design patterns too.
- seanp2k2 14y ago>"got me thinking about over engineering design patterns too." Relevant: http://me.veekun.com/blog/2013/03/03/the-controller-pattern-is-awful-and-other-oo-heresy/ http://me.veekun.com/blog/2013/03/03/the-controller-pattern-... (by the same dude who wrote "PHP: A Fractal of Bad Design", no less)
- refiammingo 14y agoWhat about subtraction now?
- michaldudek 14y agoWhat if I need to add 2 and 1? Is there a lib for that? Or would this one need to be completely refactored? Also, in what version could we expect ability to handle 2 digit (or more!) numbers?
- lzh-ng 14y agoIf you're going to implement 2+1 functionality, make sure to add the appropriate unit tests.
- igorw2 14y agoThe library supports adding other numbers than 1 and 1. Your use case of adding 2 to 1 is supported. As are multi-digit numbers. As are negative numbers. As you can see, the library is quite advanced.
- runekaagaard 14y agoWhat? No dependency injection framework? Pft! :)
- igorw2 14y agoThere's a pull request for that now. ;-)
- seanp2k2 14y agoI opened a few bugs to help get this library in a more usable state. I'd really love to see a SOAP API on this as well as result templating, a request router, and a controller. It may also be useful to include a message queue (RabitMQ / SQS are good candidates) implemented using the pub/sub model to allow arbitrary scaling of the compute nodes. I have some other ideas about something like JMX / MBeans here to allow arbitrary instrumentation of methods. This would provide more flexibility than the benchmarking module already included.
- clyfe 14y agoFrom ZF :( https://twitter.com/_clyfe/status/265588170341625857 https://twitter.com/_clyfe/status/265588170341625857
- niggler 14y agoWhile we are discussing PHP, why is the ternary operator nesting behavior different from every other mainstream language using "?" and ":" ?
- deleted 14y ago[deleted]
- mscarborough 14y agoI'm not sure, but probably historical reasons like much else in PHP. Though, I'm not a real fan of reading other people's nested ternary ops, because if you're going that deep, just write an if/then in whatever language you're using? It will keep you under 80 chars which is a polite way to go.
- leeoniya 14y agothere's a lot of stuff in PHP that bothers me...mostly consistency of function arg orders and function naming. but this has to be the one that really drives me up the wall. i cannot believe they choose to maintain this broken implementation because it's defined improperly in the spec. just yuck.
- duskwuff 14y agoPresumably: Rasmus got the precedence wrong when he wrote the parser, and it's way too late to fix it now.
- phaikawl 14y agowell github has every kind of project...
- jonascopenhagen 14y agoPretty much sums up how I feel about most of the big frameworks (Zend in particular, but also Symfony and CakePHP). The problem of over-engineering isn't just related to the big PHP frameworks - the same problem exists in Python and Ruby. At its core, web development is about taking some user input, validating it, throwing it in a database, and displaying it again (perhaps slightly modified) to users. That's a fairly simple concept, and frameworks should reflect that.
- masklinn 14y ago> The problem of over-engineering isn't just related to the big PHP frameworks - the same problem exists in Python and Ruby. OTOH, the "complexity" may also be "configurability" or "pluggability" with missing shortcuts. And quite often the "simple" version ends up being insufficient when one needs to tweak something: http://lucumr.pocoo.org/2013/2/13/moar-classes/ http://lucumr.pocoo.org/2013/2/13/moar-classes/ > That's a fairly simple concept When going for pithy statements and omitting most of the actual issues, even encryption, clustering or networking "[are] fairly simple concepts". Which effectively they're not.
- jonascopenhagen 14y agoI know what you mean, and I realize there's more to web development than what I just wrote. Nonetheless, I think frameworks such as Zend add a level of complexity that is rarely justified. Zend fans would probably claim that doing things the "right" way in the beginning means less work when you need to maintain the app three years later. I'm not so sure. To be honest, three years from now I'd rather be maintaining a CodeIgniter app than a Zend one. I'm not a CodeIgniter fan per se, and I realize that it gets a lot of criticism for being written the "wrong" way - but the point here is that simple (and well-documented) solutions often win the day.
- deleted 14y ago[deleted]
- zapu 14y ago
- nadinengland 14y agoThe functional unit tests made me laugh: https://github.com/Herzult/SimplePHPEasyPlus/blob/master/tests/Functional/AdditionTest.php#L53 https://github.com/Herzult/SimplePHPEasyPlus/blob/master/tes...
- lubujackson 14y agoUh oh, the LOLz have invaded Github. Pretty good one, though.
- lubujackson 14y agoCan't recommend because of a 0 day exploit. If you add 0 you get root via SQL injection.
- laurent123456 14y agoIt reminds me of a Zend Framework project I'm maintaining, where the previous dev apparently tried to apply any OOP pattern they've ever head about. To get anything from the db, one needs to get a "service locator" (just a dumb global object but with a cooler name) that will parse a namespace and returns a repository that will call a mapper, which in turn will instantiate an entity, which somewhere deeps in the Zend Framework is going to run an SQL query (going through dozens of classes, just to make stack-traces more readable...) and, maybe, if I'm lucky, I'll actually get some usable data back. Of course, adding a new table is just as much fun - dozens of modules, controllers, repositories, mappers and so on to create, and just as many configuration files to update. And, of course, if something's not quite right, good luck getting any sensible error from the framework.
- alexvr 14y agopoints += 500 This made my day.
- alexvr 14y agoDon't let this get too popular or people (non-HN, of course) might start using it.
- venomsnake 14y agoI love it. And I hope that after all the types of fad programming (that work almost as good as the fad diets) we will get to the "common sense programming" - use the proper tools and scale for the problem and don't try to fit the problem in your tools and frameworks.
- camus 14y agowhile i get the joke , i'm sorry , but serious PHP development means bloated frameworks. You cant avoid it. Frameworks code looks ugly because PHP looks ugly . But has anybody seen Rails source code ?Django's ? or even Sinatra's ? it is bloated too, but because Ruby and Python a well designed , when using them , you dont feel they are bloated. That's why you end up ( in PHP ) writing yaml config files for DI, ORM , etc more than actual PHP. If php looked more like Ruby or Python , using symfony 2 or ZF 2 would be less painfull. Now let's consider something else. in Python you have WSGI , Ruby Rake ,etc ... which are really good stuff , universal in the way you plug into them to write your own framework. Up until now, PHP devs felt they did not really need it. But as the PSR effort improves , we need frameworks to implement the same http kernels so we can plug any middleware no matter what the lib is , that's very important. You cant use raw PHP anymore. You need middleware you can use ACCROSS frameworks. So should php devs use frameworks ? yes. just like Ruby , Python devs dont do raw CGI programming. Should i use guzzle instead of CURL ? yes because it has a beautifull and fluent API , and CURL is just plain ugly. Should i use Silex/Slim/Laravel instead of raw PHP ? yes because your application will scale with these simple frameworks. Writing raw PHP without PSR-0 autoloading , and no framework doesnt scale , period. PHP has a real problem. I admit. It needs a real deep , breaking redesign, a clear separation between the core and libraries , and fat trimming. But framework designers did a great job trying to correct its flaws and making PHP development bearable.
- iSnow 14y ago>we need frameworks to implement the same http kernels so we can plug any middleware no matter what the lib is , that's very important. This is great news - it means PHP is going down the same route that very nearly lead Java to its death and still makes it the laughing-stock of the Dev world. PHP does not have this much traction with enterprisey enterprises, so following Java here probably means PHP is heading for a painful and ugly end. "Good news, everyone" - Prof. Farnthworth
- camus 14y agoAll web solutions use pluggable middleware ( Ruby Rake , Python WSGI , NodeJS Connect ). So PHP getting some abstraction is JAVA-ISH ?
- neya 14y agoWelcome to the enterprise world. If you are already working for a typically huge enterprise, you would have realized that this kind of coding (Engineering) is just another day at the office and people actually get paid (more) to over-engineer! Infact, anything done to reduce complexity is actually frowned upon, or will even get you labelled as an ignorant employee.
- futhey 14y agoWOW I thought I was alone all these years!