Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #15596
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Refresher for array handling??? |
| Date | 2015-07-20 19:45 +0200 |
| Organization | PointedEars Software (PES) |
| Message-ID | <2599412.tJzUQXBYqY@PointedEars.de> (permalink) |
| References | <lvbaqa189n0e1ldtgg1de1vprbjvs46es2@4ax.com> <55a6598d$0$2914$e4fe514c@news2.news.xs4all.nl> <239530657.1smQKY0v18@PointedEars.de> <55ad0600$0$2900$e4fe514c@news2.news.xs4all.nl> |
Erwin Moller wrote: > On 7/17/2015 9:24 PM, Thomas 'PointedEars' Lahn wrote: >> DRY: >> >> $frq = array( >> 12 => array(13.4, 17.4, 20.0), >> 13 => array(3.5, 6.7, 17.3), >> 19 => array(3.1, 194.45, 10.909) >> ); >> >> Since PHP 5.4: >> >> $frq = [ >> 12 => [13.4, 17.4, 20.0], >> 13 => [3.5, 6.7, 17.3], >> 19 => [3.1, 194.45, 10.909] >> ]; >> >> <http://php.net/manual/en/migration54.new-features.php> > > What is your point? > You have another syntax to create an array? That, too. > And the above "improvement" is a poor example of Don't Repeat Yourself, > in my humble opinion. > DRY is not about slashing out a few $frq in the sourcecode... Obviously you have not understood DRY. It is about _not_ *repeating* yourself in order to make code *less* error-prone and *easier* to maintain. There is no need to repeat a variable identifier here, and no need to have several statements when you can have one. This is only an example where the identifier happens to be short. Unnecessary repetition is not only time-consuming when reading and writing code, but can easily lead to inconsistencies that are even more time- consuming to spot and fix. As for PHP, the statement $bar['baz'] = 42; *creates* the $bar array if it did not exist. Suppose after refactoring the real variable name were $foo; it is possible, and it has happened even to the best of us, that in a non-trivial piece of code one will spend *hours* searching for the reason why the darn $foo array is empty. This does not happen if you initialize the array once, as I suggested, or merge with another array later. >>> […] >>> echo "<pre>"; >> ^^ >> echo '<pre>' . print_r($frq, true) . '</pre>'; >> >> <http://php.net/print_r> >> >> With the Xdebug extension enabled, >> >> var_dump($frq); >> >> will generate the output using a fixed-width font by default, and you >> have more control over the output, such as the nesting level. >> >> <http://xdebug.org/docs/display> > > ??? > I try to tell the OP how to inspect his data structure, a worthwhile > idea for newcomers, and your extra info added nothing. It did add *a lot*. *And* I pointed out a mistake that you made that would cause the output of the OP to be displayed with a fixed-width font (in the best case) starting at that line. > Could you please stop making such observations??? Could you please read what you are replying to? And fix your Question Mark key. > It is noise. It is not, by contrast to what you are making here and now. >>> ?> >> >> Avoid this in PHP programs unless you are sure that you want what follows >> to be sent to the standard output. > > I don't agree with that attitude. It is not an attitude, it is a recommendation. One that is confirmed by previous PHP coding standards, and by *the* current PHP Coding Style Guide (PSR-2) which extends *the* current PHP Basic Coding Standard (PSR-1), all of which I referred to. > Leaving out ?> at the end is one of the worst ideas PHP ever came up > with, and I won't support it. Explain that to the many people who wondered why their HTTP headers were not sent after including a library. > If one doesn't know what ?> means, and one is surprised by the fact that > what follows after ?> is send to standard output, one should not be > programming.... Not knowing what “?>” means is not the point here; I have not even given indication that it would be. Avoiding error-prone code is. >> <http://www.php-fig.org/psr/psr-2/> etc. > > Do you really care for that Coding Style Guide? I do, and several thousands of other professional PHP developers. > I don't. Why should anyone care about your humble opinion? You are evidentially only an amateur when it comes to PHP programming; that is why you do not care about “that Coding Style Guide”. Or is it vice-versa? Anyhow, you would be well-advised to listen instead. Score adjusted -- PointedEars Zend Certified PHP Engineer Twitter: @PointedEars2 Please do not cc me. / Bitte keine Kopien per E-Mail.
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Refresher for array handling??? bobmct <r.mariotti@fdcx.net> - 2015-07-14 12:12 -0400
Re: Refresher for array handling??? Erwin Moller <erwinmollerusenet@xs4all.nl> - 2015-07-15 15:01 +0200
Re: Refresher for array handling??? Erwin Moller <erwinmollerusenet@xs4all.nl> - 2015-07-15 15:03 +0200
Re: Refresher for array handling??? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-17 21:24 +0200
Re: Refresher for array handling??? Erwin Moller <erwinmollerusenet@xs4all.nl> - 2015-07-20 16:30 +0200
Re: Refresher for array handling??? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-20 19:45 +0200
Re: Refresher for array handling??? Matthew Carter <m@ahungry.com> - 2015-07-20 22:36 -0400
Re: Refresher for array handling??? Erwin Moller <erwinmollerusenet@xs4all.nl> - 2015-07-21 11:22 +0200
Re: Refresher for array handling??? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-21 13:30 +0200
Re: Refresher for array handling??? Erwin Moller <erwinmollerusenet@xs4all.nl> - 2015-07-21 14:03 +0200
Re: Refresher for array handling??? Denis McMahon <denismfmcmahon@gmail.com> - 2015-07-21 01:01 +0000
Re: Refresher for array handling??? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-21 09:07 +0200
Re: Refresher for array handling??? "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-07-15 20:18 +0200
Re: Refresher for array handling??? Denis McMahon <denismfmcmahon@gmail.com> - 2015-07-17 02:51 +0000
csiph-web