TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-10-2009, 02:07 AM   #1 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 687
Thanks: 240
codefreek is on a distinguished road
Help 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
__________________
I will be Offline for a while, (Working)..
codefreek is offline  
Reply With Quote
Old 06-10-2009, 02:23 AM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,215
Thanks: 90
Wildhoney is on a distinguished road
Default

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.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
The Following User Says Thank You to Wildhoney For This Useful Post:
Runar (06-10-2009)
Old 06-10-2009, 02:40 AM   #3 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 687
Thanks: 240
codefreek is on a distinguished road
Default

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..
__________________
I will be Offline for a while, (Working)..
codefreek is offline  
Reply With Quote
Old 06-10-2009, 03:50 AM   #4 (permalink)
The Acquainted
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 158
Thanks: 8
tony is on a distinguished road
Default

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
tony is offline  
Reply With Quote
Old 06-11-2009, 08:38 AM   #5 (permalink)
The Contributor
 
Sakakuchi's Avatar
 
Join Date: Feb 2009
Posts: 65
Thanks: 1
Sakakuchi is on a distinguished road
Default

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.
Sakakuchi is offline  
Reply With Quote
Old 06-11-2009, 03:11 PM   #6 (permalink)
The Acquainted
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 158
Thanks: 8
tony is on a distinguished road
Default

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.
tony is offline  
Reply With Quote
Old 06-11-2009, 06:39 PM   #7 (permalink)
Super Moderator
Inquisitive 
 
codefreek's Avatar
 
Join Date: Sep 2007
Location: Near you.
Posts: 687
Thanks: 240
codefreek is on a distinguished road
Default

Tony, i am a person with many talents ;)
__________________
I will be Offline for a while, (Working)..
codefreek is offline  
Reply With Quote
Old 06-11-2009, 08:24 PM   #8 (permalink)
The Acquainted
 
Randy's Avatar
 
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
Randy is on a distinguished road
Default

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
Send a message via AIM to Randy Send a message via MSN to Randy
Randy is offline  
Reply With Quote
Old 06-11-2009, 09:06 PM   #9 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,216
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by Wildhoney View Post
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.
Village Idiot is offline  
Reply With Quote
Old 06-15-2009, 07:49 AM   #10 (permalink)
The Contributor
 
Join Date: Jun 2009
Location: Seattle, WA
Posts: 79
Thanks: 1
rguy84 is on a distinguished road
Default

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
__________________
Ryan | Blog | Twitter
Send a message via AIM to rguy84 Send a message via MSN to rguy84 Send a message via Yahoo to rguy84 Send a message via Skype™ to rguy84
rguy84 is offline  
Reply With Quote
Old 06-24-2009, 11:56 PM   #11 (permalink)
The Wanderer
 
Mike's Avatar
 
Join Date: Jun 2009
Posts: 11
Thanks: 0
Mike is on a distinguished road
Default

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
Mike is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
print() vs echo() allworknoplay Absolute Beginners 9 05-27-2009 01:46 PM
Call what is to print from the array ? Peuplarchie General 2 04-09-2009 08:17 PM
how do you do a automatic status print on website like this codefreek General 2 10-25-2008 04:43 PM
No idea where to start. damien Absolute Beginners 14 12-23-2007 02:30 PM


All times are GMT. The time now is 10:01 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design