Re: Re: Re: [PHP] What's Your Favorite Design Pattern?

2012-02-10 Thread Jeremiah Dodds
On Wed, Feb 8, 2012 at 12:48 PM, Paul M Foster pa...@quillandmouse.com wrote:
 Um, yeah. It's very meta.

 (That's what I love about The C Programming Language. It's a little
 over half an inch thick in paperback, explains the whole language
 clearly and concisely, and has barely been revised since 1988. I'm not
 sure you could ask for more in a technical book.)

The C Programming Language is an exemplary language book -- it's
well-laid-out, and you can pick it up as a complete novice and end up
with enough of a grounding to get you going.

I don't share quite your level of distaste for Design Patterns, or the
GoF book. I found it pretty useful to read through, and was introduced
to some interesting ways of solving problems I had seen before. Minus
Singleton ;) I also found reading through the first part of the book
to be pretty enlightening. It's more than possible that a lot of the
benefit that I got from the book came from the experience-level I was
at when I read it -- I hadn't worked on any systems that I couldn't
fit entirely in my head at the time.

Most of the problems I've had with code that uses design patterns
have been with code where the authors used the patterns in a
prescriptive manner -- like they were looking for ways to fit their
problem into a neat architecture that they didn't need and didn't
understand. I don't think they were (or are) meant to be used in that
manner, they're supposed to be part of a shared language for
high-level patterns used to solve particular families of architecture
issues when they're needed. Letting the existing names and
implementations and suggested use-cases of design patterns dictate
your codebase is a recipe for disaster.

I also happen to agree with the idea that the existence of design
patterns can be a language-deficiency smell, but hey, we don't always
get to work with the languages we prefer to work with.

Anyhow, that's my two cents.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: Re: Re: [PHP] What's Your Favorite Design Pattern?

2012-02-08 Thread Tim Streater
On 07 Feb 2012 at 22:31, Paul M Foster pa...@quillandmouse.com wrote: 

 Design Patterns are Way Nifty Kewl patterns of code which are supposed
 to facilitate certain types of operations. (Was that sarcasm you
 detected? Yes it was.)

 For example, the Singleton pattern. Let's say you had a configuration
 class that held the configuration values for your application, and you
 wanted to make sure there was only one object of that class
 instantiated, no matter how many times it was called in your code. You'd
 arrange the code and call the class in a certain way to ensure that only
 one object of that class resulted. To make your configuration class a
 singleton, you'd probably make the class have a *private* constructor
 (so no outside routine could call it), and then provide a method called
 get_instance() which tested for the existence of an object of that
 class. If such an instance was found, someone calling
 configuration::get_instance() would simply get the existing object
 returned to them. Otherwise, configuration::get_instance() would
 instantiate the class and then return the new object to the caller.

 As you can see, that's a peculiar way of setting up your code for a
 specific purpose. Other design patterns do other things and dictate
 setting up things in other ways.

 The definitive work on this (and where it first gained the most
 publicity) is a book called Design Patterns by four authors (Gamma,
 Helm, Johnson and Vlissides). It essentially contains a chapter about
 each (known at the time) design pattern and some pseudocode about how it
 might be constructed. I imagine the authors looked at a lot of code and
 discovered that programmers were coming up with code that, in each case
 was remarkably similar for solving certain types of programming
 problems. So they codified what that found and wrote a book about it.

 I have the book on my shelf, and it's decent technology, but you could
 spend your whole career and never use any of it, and get along just
 fine.

Mmmm. Well, at this point I feel underwhelmed - but its entirely possible that 
I'm missing something profound [1]. After looking at some of the reviews of the 
book you mention on Amazon, I might be inclined to get a simpler intro.

[1] In June 1982 (or was it '83?) I visited PARC with a small group from SLAC. 
We saw the Star or whatever it was, with bit-mapped display and mouse pointer. 
Whoosh !! (Well, to be fair, we'd gone along to look into XNS).

--
Cheers  --  Tim

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Re: Re: [PHP] What's Your Favorite Design Pattern?

2012-02-08 Thread Paul M Foster
On Wed, Feb 08, 2012 at 02:25:00PM +, Tim Streater wrote:


[snip]

 
 Mmmm. Well, at this point I feel underwhelmed - but its entirely
 possible that I'm missing something profound [1]. 


Not really. 

 After looking at some of the reviews of the book you mention on
 Amazon, I might be inclined to get a simpler intro.

Um, yeah. It's very meta. 

(That's what I love about The C Programming Language. It's a little
over half an inch thick in paperback, explains the whole language
clearly and concisely, and has barely been revised since 1988. I'm not
sure you could ask for more in a technical book.)

 
 [1] In June 1982 (or was it '83?) I visited PARC with a small group
 from SLAC. We saw the Star or whatever it was, with bit-mapped display
 and mouse pointer. Whoosh !! (Well, to be fair, we'd gone along to
 look into XNS).
 

I remember working for Xerox (copy center employee) around that time,
and seeing all kinds of talk in the company materials about *Ethernet*.
They explained the basic protocol and compared it to token ring, and I
just thought, Hmm, yes, that seems like a pretty clever way to go about
networking.

Paul

-- 
Paul M. Foster
http://noferblatz.com
http://quillandmouse.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] What's Your Favorite Design Pattern?

2012-02-07 Thread admin
 -Original Message-
 From: Mike Mackintosh [mailto:mike.mackint...@angrystatic.com]
 Sent: Tuesday, February 07, 2012 1:57 PM
 To: PHP General List
 Subject: [PHP] What's Your Favorite Design Pattern?
 
 I was curious to see what everyones favorite design patterns were, if
 you use any, and why/when have you used it?
 
 Choices include slots and signals (observer), singleton, mvc, hmvc,
 factory, commander etc..
 
 Thanks,
 
 --
 Mike Mackintosh
 PHP, the drug of choice - www.highonphp.com
 
 


MVC because it allows the most flexibility and I use it every day.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] What's Your Favorite Design Pattern?

2012-02-07 Thread Adam Richardson
On Tue, Feb 7, 2012 at 1:56 PM, Mike Mackintosh 
mike.mackint...@angrystatic.com wrote:

 I was curious to see what everyones favorite design patterns were, if you
 use any, and why/when have you used it?

 Choices include slots and signals (observer), singleton, mvc, hmvc,
 factory, commander etc..


Higher-order functions:

http://programmers.stackexchange.com/questions/72557/how-do-you-design-programs-in-haskell-or-other-functional-programming-languages

Adam

-- 
Nephtali:  A simple, flexible, fast, and security-focused PHP framework
http://nephtaliproject.com


Re: [PHP] What's Your Favorite Design Pattern?

2012-02-07 Thread Fatih P.
mostly MVC, Singleton and Factory. depends on requirements.


Re: [PHP] What's Your Favorite Design Pattern?

2012-02-07 Thread Daniel Brown
On Tue, Feb 7, 2012 at 13:56, Mike Mackintosh
mike.mackint...@angrystatic.com wrote:
 I was curious to see what everyones favorite design patterns were, if you use 
 any, and why/when have you used it?

 Choices include slots and signals (observer), singleton, mvc, hmvc, factory, 
 commander etc..

Mine is apparently CPSV (Commentless Procedural Spaghetti Vomit),
as that's what I encounter no less than 80% of the time in the wild.

-- 
/Daniel P. Brown
Network Infrastructure Manager
http://www.php.net/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] What's Your Favorite Design Pattern?

2012-02-07 Thread Bastien

On 2012-02-07, at 2:34 PM, Daniel Brown danbr...@php.net wrote:

 On Tue, Feb 7, 2012 at 13:56, Mike Mackintosh
 mike.mackint...@angrystatic.com wrote:
 I was curious to see what everyones favorite design patterns were, if you 
 use any, and why/when have you used it?
 
 Choices include slots and signals (observer), singleton, mvc, hmvc, factory, 
 commander etc..
 
Mine is apparently CPSV (Commentless Procedural Spaghetti Vomit),
 as that's what I encounter no less than 80% of the time in the wild.
 
 -- 
 /Daniel P. Brown
 Network Infrastructure Manager
 http://www.php.net/
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

I think you should trademark that, Dan 

Bastien Koert
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: Re: [PHP] What's Your Favorite Design Pattern?

2012-02-07 Thread Tim Streater
On 07 Feb 2012 at 19:34, Daniel Brown danbr...@php.net wrote: 

 On Tue, Feb 7, 2012 at 13:56, Mike Mackintosh
 mike.mackint...@angrystatic.com wrote:
 I was curious to see what everyones favorite design patterns were, if you use
 any, and why/when have you used it?

 Choices include slots and signals (observer), singleton, mvc, hmvc, factory,
 commander etc..

Mine is apparently CPSV (Commentless Procedural Spaghetti Vomit),
 as that's what I encounter no less than 80% of the time in the wild.

Since I have no idea what anyone is talking about, I can only conclude that 
you're playing Mornington Crescent (q.v.), on a non-standard board.

--
Cheers  --  Tim

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Re: [PHP] What's Your Favorite Design Pattern?

2012-02-07 Thread Paul M Foster
On Tue, Feb 07, 2012 at 09:02:00PM +, Tim Streater wrote:

 On 07 Feb 2012 at 19:34, Daniel Brown danbr...@php.net wrote: 
 
  On Tue, Feb 7, 2012 at 13:56, Mike Mackintosh
  mike.mackint...@angrystatic.com wrote:
  I was curious to see what everyones favorite design patterns were, if you 
  use
  any, and why/when have you used it?
 
  Choices include slots and signals (observer), singleton, mvc, hmvc, 
  factory,
  commander etc..
 
 Mine is apparently CPSV (Commentless Procedural Spaghetti Vomit),
  as that's what I encounter no less than 80% of the time in the wild.
 
 Since I have no idea what anyone is talking about, I can only conclude that 
 you're playing Mornington Crescent (q.v.), on a non-standard board.
 
 --
 Cheers  --  Tim
 

Design Patterns are Way Nifty Kewl patterns of code which are supposed
to facilitate certain types of operations. (Was that sarcasm you
detected? Yes it was.)

For example, the Singleton pattern. Let's say you had a configuration
class that held the configuration values for your application, and you
wanted to make sure there was only one object of that class
instantiated, no matter how many times it was called in your code. You'd
arrange the code and call the class in a certain way to ensure that only
one object of that class resulted. To make your configuration class a
singleton, you'd probably make the class have a *private* constructor
(so no outside routine could call it), and then provide a method called
get_instance() which tested for the existence of an object of that
class. If such an instance was found, someone calling
configuration::get_instance() would simply get the existing object
returned to them. Otherwise, configuration::get_instance() would
instantiate the class and then return the new object to the caller.

As you can see, that's a peculiar way of setting up your code for a
specific purpose. Other design patterns do other things and dictate
setting up things in other ways.

The definitive work on this (and where it first gained the most
publicity) is a book called Design Patterns by four authors (Gamma,
Helm, Johnson and Vlissides). It essentially contains a chapter about
each (known at the time) design pattern and some pseudocode about how it
might be constructed. I imagine the authors looked at a lot of code and
discovered that programmers were coming up with code that, in each case
was remarkably similar for solving certain types of programming
problems. So they codified what that found and wrote a book about it.

I have the book on my shelf, and it's decent technology, but you could
spend your whole career and never use any of it, and get along just
fine. 

Paul

-- 
Paul M. Foster
http://noferblatz.com
http://quillandmouse.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RES: [PHP] What's Your Favorite Design Pattern?

2012-02-07 Thread Alejandro Michelin Salomon
Mike:

My favorite are singleton ( database connection configuration ), and
factory.

Factory i use when need one code exporting or doing different process. 

Basically y have a base class with general code and a specific class that
extend the base class with code specific to the process to be made.
The main code only pass the type of format ant factory returns de right code
for the operation.

The main code remains untouched, when the factory chance each time a i need
other type of process or exportation results.

Alejandro M.S.

-Mensagem original-
De: Mike Mackintosh [mailto:mike.mackint...@angrystatic.com] 
Enviada em: terça-feira, 7 de fevereiro de 2012 16:57
Para: PHP General List
Assunto: [PHP] What's Your Favorite Design Pattern?

I was curious to see what everyones favorite design patterns were, if you
use any, and why/when have you used it?

Choices include slots and signals (observer), singleton, mvc, hmvc, factory,
commander etc..

Thanks,

--
Mike Mackintosh
PHP, the drug of choice - www.highonphp.com





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: Re: [PHP] What's Your Favorite Design Pattern?

2012-02-07 Thread Tommy Pham
On Tue, Feb 7, 2012 at 2:31 PM, Paul M Foster pa...@quillandmouse.com wrote:
 On Tue, Feb 07, 2012 at 09:02:00PM +, Tim Streater wrote:

 On 07 Feb 2012 at 19:34, Daniel Brown danbr...@php.net wrote:

  On Tue, Feb 7, 2012 at 13:56, Mike Mackintosh
  mike.mackint...@angrystatic.com wrote:
  I was curious to see what everyones favorite design patterns were, if you 
  use
  any, and why/when have you used it?
 
  Choices include slots and signals (observer), singleton, mvc, hmvc, 
  factory,
  commander etc..
 
     Mine is apparently CPSV (Commentless Procedural Spaghetti Vomit),
  as that's what I encounter no less than 80% of the time in the wild.

 Since I have no idea what anyone is talking about, I can only conclude that 
 you're playing Mornington Crescent (q.v.), on a non-standard board.

 --
 Cheers  --  Tim


 Design Patterns are Way Nifty Kewl patterns of code which are supposed
 to facilitate certain types of operations. (Was that sarcasm you
 detected? Yes it was.)

 For example, the Singleton pattern. Let's say you had a configuration
 class that held the configuration values for your application, and you
 wanted to make sure there was only one object of that class
 instantiated, no matter how many times it was called in your code. You'd
 arrange the code and call the class in a certain way to ensure that only
 one object of that class resulted. To make your configuration class a
 singleton, you'd probably make the class have a *private* constructor
 (so no outside routine could call it), and then provide a method called
 get_instance() which tested for the existence of an object of that
 class. If such an instance was found, someone calling
 configuration::get_instance() would simply get the existing object
 returned to them. Otherwise, configuration::get_instance() would
 instantiate the class and then return the new object to the caller.

 As you can see, that's a peculiar way of setting up your code for a
 specific purpose. Other design patterns do other things and dictate
 setting up things in other ways.


Here's a code example of the above explanation:

http://pastebin.com/mTrybi6u

HTH,
Tommy


 The definitive work on this (and where it first gained the most
 publicity) is a book called Design Patterns by four authors (Gamma,
 Helm, Johnson and Vlissides). It essentially contains a chapter about
 each (known at the time) design pattern and some pseudocode about how it
 might be constructed. I imagine the authors looked at a lot of code and
 discovered that programmers were coming up with code that, in each case
 was remarkably similar for solving certain types of programming
 problems. So they codified what that found and wrote a book about it.

 I have the book on my shelf, and it's decent technology, but you could
 spend your whole career and never use any of it, and get along just
 fine.

 Paul

 --
 Paul M. Foster
 http://noferblatz.com
 http://quillandmouse.com

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php