
Addition of 1 and 1 in PHP - gcmalloc
https://github.com/Herzult/SimplePHPEasyPlus
======
jonascopenhagen
Pretty 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
> 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/>

> 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
I 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.

------
flatline
The 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
See, 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.

------
Mahn
Reminds me of something I wrote a few months ago on how to detect negative
numbers: <http://stackoverflow.com/a/11910993/1329367> but obviously the one
above has much more value add and follows better design patterns.

~~~
UnoriginalGuy
You have to have a sick mind to come up with something like that, I salute you
sir.

------
seanp2k2
I 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.

------
laurent123456
It 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.

------
neya
Welcome 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.

------
nadinengland
The functional unit tests made me laugh:
[https://github.com/Herzult/SimplePHPEasyPlus/blob/master/tes...](https://github.com/Herzult/SimplePHPEasyPlus/blob/master/tests/Functional/AdditionTest.php#L53)

~~~
bjxrn
What!? No mock classes?

~~~
pjscott
All of the classes in this were created for the purpose of mockery.

------
babuskov
I know a couple of Java programmers that will find this helpful. Thanks.

~~~
drivingmenuts
What Java really needs is a KitcheSink class.

I'm pretty sure there's already one in PHP.

~~~
Joeri
No, but it has a bunch of kitchensnk_ functions in the kitchensnk extension.

~~~
pavel_lishin
Those have been deprecated, you really need to be using the real_ksink
functions.

Be careful, though, the argument order swapped.

~~~
pixl97
Is 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>

------
nicholaides
I'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
I 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 ;)

~~~
jonascopenhagen
> I have yet to see any Java-style absurdity.

Then you probably haven't tried Zend Framework ;)

~~~
polychrome
So what am I in for with Drupal 8 since the two communities are combining?

~~~
msp
Drupal 8 will use Symfony2 components, not Zend.

~~~
polychrome
Thanks for correcting me msp. I must have misread that!

------
sneak
Oh, did someone port Twisted to PHP?

------
venomsnake
I 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.

------
zerovox
The 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.

------
merinid
This 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
>"got me thinking about over engineering design patterns too."

Relevant: [http://me.veekun.com/blog/2013/03/03/the-controller-
pattern-...](http://me.veekun.com/blog/2013/03/03/the-controller-pattern-is-
awful-and-other-oo-heresy/) (by the same dude who wrote "PHP: A Fractal of Bad
Design", no less)

~~~
solistice
I'm going to check whether I still have vodka somewhere around my place,
because I want to forget some code real fast.

------
BjoernKW
Hooray for enterprise software 'design patterns'.

------
runekaagaard
What? No dependency injection framework? Pft! :)

~~~
igorw2
There's a pull request for that now. ;-)

------
alexvr
Don't let this get too popular or people (non-HN, of course) might start using
it.

------
michaldudek
What 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?

~~~
igorw2
The 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.

------
clyfe
From ZF :( <https://twitter.com/_clyfe/status/265588170341625857>

------
niggler
While we are discussing PHP, why is the ternary operator nesting behavior
different from every other mainstream language using "?" and ":" ?

~~~
leeoniya
there'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.

------
lubujackson
Can't recommend because of a 0 day exploit. If you add 0 you get root via SQL
injection.

------
juskrey
An example is pretty good, but I am not sure about scalability and load
balancers.

~~~
Mahn
I 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.

------
lubujackson
Uh oh, the LOLz have invaded Github. Pretty good one, though.

------
pestaa
Yes 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
Oh come on, PHP is a dynamically typed language. That's the trade.

~~~
pestaa
Strong 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.

------
futhey
WOW I thought I was alone all these years!

------
refiammingo
What about subtraction now?

~~~
igorw2
Negative numbers are supported. But if you want a clean solution, implementing
a SubtractionOperator is easy enough. Just implement the OperatorInterface.

------
canibanoglu
Hilarious!

------
jordan_clark
Good one.

------
alexvr
points += 500

This made my day.

------
camus
while 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
>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
All web solutions use pluggable middleware ( Ruby Rake , Python WSGI , NodeJS
Connect ). So PHP getting some abstraction is JAVA-ISH ?

~~~
pjscott
I notice that all of those things are internally simple. No bloat required.

