 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
 |
|
 |
06-10-2009, 02:07 AM
|
#1 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
|
Tired of Print - (Just an idea lol)
PS: i know, I have to much time on my hands haha
Print, Got Owned ;)
PHP Code:
<?php // End the Use of print : ) function p($s = "") { print $s; } p(lol); ?>
Quote:
in theory you will use less text p? then print.
/just a thought
|
-Cf
|
|
|
|
06-10-2009, 02:23 AM
|
#2 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
Hehe. Nonsense! But perhaps we can evolve this thread into something a little more meaningful
I used to wrap a lot of my items in functions. For $_GET I used to have g(), $_POST was p(), and $_GET/ $_POST was gp(). These are all fine and dandy but they don't describe too well what is happening inside that function. Whether it's setting or getting, what it's setting or getting.
I was working with the open-source eCommerce system, Magento, a couple of weeks ago now, and I noticed, much to my disgust, that they were using function names with two underscores ( __) to print labels. What were they thinking?
For instance:
php Code:
function __ ($szText){ return $szText; }echo __ ('I love TalkPHP');
As it is, however, I much prefer the use of print and echo. They describe well what is happening, and in themselves they are not functions, but rather language constructs. Wrapping them in functions, insofar as I see, isn't preferable, particularly in terms of readability.
In addendum, I even dislike using printf , especially in amongst echoes and prints, because, from a superficial perspective, they are highlighted differently in Zend Studio, and the printf requires the items to be passed as arguments, unlike print and echo. It creates a mess!
I now always follow the rule that everything must describe, as best as they can, what its purpose is.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|
|
The Following User Says Thank You to Wildhoney For This Useful Post:
|
|
06-11-2009, 09:06 PM
|
#3 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
Quote:
Originally Posted by Wildhoney
Hehe. Nonsense! But perhaps we can evolve this thread into something a little more meaningful
I used to wrap a lot of my items in functions. For $_GET I used to have g(), $_POST was p(), and $_GET/ $_POST was gp(). These are all fine and dandy but they don't describe too well what is happening inside that function. Whether it's setting or getting, what it's setting or getting.
I was working with the open-source eCommerce system, Magento, a couple of weeks ago now, and I noticed, much to my disgust, that they were using function names with two underscores ( __) to print labels. What were they thinking?
For instance:
php Code:
function __ ($szText){ return $szText; }echo __ ('I love TalkPHP');
As it is, however, I much prefer the use of print and echo. They describe well what is happening, and in themselves they are not functions, but rather language constructs. Wrapping them in functions, insofar as I see, isn't preferable, particularly in terms of readability.
In addendum, I even dislike using printf , especially in amongst echoes and prints, because, from a superficial perspective, they are highlighted differently in Zend Studio, and the printf requires the items to be passed as arguments, unlike print and echo. It creates a mess!
I now always follow the rule that everything must describe, as best as they can, what its purpose is.
|
Printf was passed on from C to PHP. Since PHP is loosely typed and allows automatic siring joining, printf is effectively useless. However in C, things are harder. Printf is the best way to output things in C. Likewise, sprintf is the easist way to assemble a string together. In C, a string is an array of chars (one charictar), so C works with the following
Code:
//bad assignment
char x;
x = "Hello World";
//bad assignment
char x[3];
x="Hello World";
//Valid assignment
char x[4];
x="Hello";
x="12345";
//Attachment
char x[4];
char y[4];
char xy[9];
x="Hello"
y="World"
xy = x+y; //Bad
xy = x&y; //Bad
xy = x.y; //Bad
sprintf(xy,"%s%s",x,y) //Good
As you can see, sprintf is the easiest way in standard C to join strings. There is a library that makes strings work something closer like what they do in PHP, but that is not as platform independent.
|
|
|
|
06-10-2009, 02:40 AM
|
#4 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
|
Thanks for the comment. ;) // always so insightful :)
and hum Magento a (__) thats yeah hum.. maybe a typo XD how
epic would that be if it was a typo hehe..
|
|
|
|
06-10-2009, 03:50 AM
|
#5 (permalink)
|
|
The Addict
Join Date: Aug 2008
Posts: 336
Thanks: 8
|
jeje, solia hacerlo todo el tiempo con java para hacer el System.out.println() corto a println() pero con php no es tanto escribir print o echo, ademas de que me gusta el sintaxis de concatenar con comas en la declarativa de echo.
Nota Personal: Buscar otra alternative de eCommerce y no usar magento. jaja
Translation:
Quote:
I used to do it all the time with java to do the System.out.println () to short println () with php but not so much to write print or echo, plus I like the syntax for concatenating with commas in the declaration of echo.
Personal Note: Find another alternative to not using eCommerce and magento.
|
English Please.
Translation Added - By: CodeFreak
Last edited by codefreek : 06-10-2009 at 04:34 PM.
Reason: Translation Added - By: CodeFreak
|
|
|
|
06-11-2009, 08:38 AM
|
#6 (permalink)
|
|
The Contributor
Join Date: Feb 2009
Posts: 64
Thanks: 1
|
it's quite funny, I recently had a system on my desk which also used __ for printing. But that stuff went through an translation system later on.
|
|
|
|
06-11-2009, 03:11 PM
|
#7 (permalink)
|
|
The Addict
Join Date: Aug 2008
Posts: 336
Thanks: 8
|
I like p() better than __() at least it refers to printing somewhat. :P
is echo/print too long to use?
P.S. my bad :P The weird thing is that originally I wrote it in English then translate it to Spanish. I must of thought to be in another forum.
Thanks for the translation CodeFreak, I didn't know you know Spanish.
|
|
|
|
06-11-2009, 06:39 PM
|
#8 (permalink)
|
|
Super Moderator
Join Date: Sep 2007
Location: Near you.
Posts: 791
Thanks: 241
|
Tony, i am a person with many talents ;)
|
|
|
|
06-11-2009, 08:24 PM
|
#9 (permalink)
|
|
The Acquainted
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
|
I am going to agree with wildhoney, its nice to make it shorter to type however there is still the issue of remember what letter stands for what.
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
|
|
|
06-15-2009, 07:49 AM
|
#10 (permalink)
|
|
The Contributor
Join Date: Jun 2009
Location: Seattle, WA
Posts: 76
Thanks: 1
|
WordPress has a __() function. I forget the details but if you said __('Archives') the word archives would be translated into the visitors language. I don't know why the whole site wasn't wrappped by default but whatever
|
|
|
06-24-2009, 11:56 PM
|
#11 (permalink)
|
|
The Wanderer
Join Date: Jun 2009
Posts: 11
Thanks: 0
|
well... the __() function is more a gettext function, for i18n, wordpress has this function to return translated strings.
Wordpress also wrap echo __('some text') in _e('some text')
I guess creating "shorcuts" is a good idea when you have to repeat a lot of preoccesses over and over again, but in other hand, creating your "own language" is not a good idead, at least your developing a framework :P
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|