r/programming • • Jun 29 '14

Stop abusing arrays in PHP [xpost from /r/php]

http://nomad.so/2014/06/stop-abusing-arrays-in-php/
0 Upvotes

10 comments sorted by

3

u/[deleted] Jun 29 '14

Regarding Gary Willoughby you are inexperienced, don't understand object oriented programming and live in the past if you use arrays.

Gary Willoughby knows what processor classes are, he knows Martin Fowler, but Martin Fowler doesn't know him, he also knows the anemic domain model anti-pattern and object oriented programming. He also uses many exclamation marks which means he is right.

Gary Willoughby is even shocked that extremely popular e-commerce companies use anti patterns. He claims to be 15 year experienced software engineer; I'd expect people like this not to be shocked anymore; by nothing.

He also blogs about vim being the only editor you will ever need.

Given his example it's totally correct to use iterator classes but he judges people without questioning what their use-cases are. This is very, very shortsighted and not what people want to read.

I've seen many examples where collections were overused which lead to bad software design as well.

At the end of his post he says that "arrays are not evil but should only be used when a collection of data has no associated behaviour." which is the most seen use-case I've seen in my career. If you need behaviour, you probably end up writing a class anyway; without needing to read this blog post.

Given that last statement, his post doesn't make much sense. Why is he constructing such a strange example to show off his smartness? Oh there I said it.

My advice to Gary Willoughby is to write fewer rants but informative articles instead that don't include judgment. People like that more, I promise.

0

u/[deleted] Jun 29 '14

I wrote this because I'm fed up of dealing with poor code written by so called professionals who should know better.

Only PHP developers argue against best practise and good design even when they are eyeballs deep in awful code.

3

u/stesch Jun 29 '14

I guess Lerdorf's talk about OO being slow had made a huge impression on PHP users.

2

u/hesterbest Jun 29 '14

I switch between arrays and object, but try to remain true to one of them within each project. It really depends on the project. I find it a lot easier and quicker to just go with arrays. However, objects seems like a safer and more correct way (all though it probably adds a lit more overhead).

Also, for me in PHP it is a big win just to do json_encode() on an array. It does not work as easy on an object.

Bottom line, I do not consider this "abuse" of arrays, I consider arrays a worthy alternative to objects which in many cases helps me solve a problem faster than I will with objects. I really do not get why that nicely formatted code of multidimensional array is "..truly horrendous code abusing arrays..".

3

u/coffeedrinkingprole Jun 29 '14

Well that's fine if you're just writing disposable code, but-

No, wait, it's PHP. Carry on.

0

u/banister Jun 29 '14

Why the heck do php programmers call that an array? it's clearly a hash/dictionary.

3

u/mostly_kittens Jun 29 '14

Associative array is another word for dictionary

1

u/banister Jun 29 '14

Yes, but then you need to use the prefix 'associative'. The naked term 'array', in nearly every popular language refers to the simple, efficient integer indexed datatype found in languages like C, Python, Ruby, Java, Haskell, etc.

1

u/joyfield Jun 29 '14

Gonna bookmark because i am too lazy to switch from PHP and i am really abusing it in many ways.

-2

u/banister Jun 29 '14

php.

EDIT: lol