You are here: Re: Zip some folders and send by email « PHP Programming Language « IT news, forums, messages
Re: Zip some folders and send by email

Posted by Richard Levasseur on 12/17/49 11:52

whosaid@what.net wrote:
> In article <ca40b2dtjr2l0cd0e2lcpvmshpu4mq8h9o@4ax.com>, timr@probo.com
> says...
> > nark <nark.l@home.home.com> wrote:
>
> > >Please forgive a silly question but can you tell me why you made it a
> > >"class" rather than a simple set of functions?
> >
> > It's fascinating that you would ask this question, and I suspect a PHP
> > newsgroup is the only one in which the value of encapsulation would be
> > questioned.
> >
> > By defining a class, he is adding only one new name to the namespace,
> > instead of a whole set of names that might conflict with functions I
> > already have. In addition, it allows him to hide whatever state he might
> > need in the class object, instead of again polluting the namespace with
> > globals.
> >
> > I know the PHP philosophy is to plop 100 functions into the global
> > namespace where one class name would do, but I suspect PHP programs would
> > be easier to read and maintain if the library were reorganized as classes
> > instead.
> > --
> > - Tim Roberts, timr@probo.com
> > Providenza & Boekelheide, Inc.
> >
>
> Totally the reverse.
>
> By wrapping it in a class he has made the code unnecessarily complex
> and obtuse to read making understanding of the function difficult
> and the code therefore harder to read and maintain.
>
> The use of classes for small amounts of code such as used by PHP
> programmers writing what are not much more than a simple series of
> scripts is plain stupid and says more about the ego of the programmer
> than anything else.
>
> Anything that actually requires classes should bedone in a real reliable
> language not a buggy script language like PHP.

try {
$zip = new ZipFile('foo.zip');
$zip->addFile($myFile);
$zip->addFile($file2);
$zip->write();
} catch { 'error making zipfile' }

vs:

$zip = zipfile_new('foo.zip');
if($zip == false) { die('couldn't creat file'); }
if(!zipfile_addfile($zip, $myfile)) { die('couldn't add file'); }
if(!zipfile_addfile($zip, $myfile2)) { die('couldn't add file 2'); }
if(!zipfile_write($zip)) {
die('couldn't write zipfile');
} else { 'do whatever' }

Which is more obtuse and harder to read is a matter of opinion, really.
Not to mention i didn't bother putting line breaks in because i hate
having to indent with spaces manually.

There are a whole bunch of other things that could be done, too, such
as, maybe he wants to use Rar compression or some other scheme in the
future. Simple: change new ZipFile to new RarFile, compared to
rewriting every zipfile_* function call. I could rail on about why
using the oop method would be more advantageous than the procedural
method, but it's such a dead subject.

Whichever you use is up to you, php doesn't require you to write in any
specific way.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация