Go Back   vb.org Archive > Community Central > Community Lounge
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 03-09-2003, 10:47 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default (condition ? true : false) and other boolean goodness

It seems like a lot of people don't know about these two gems. The first is inline if. vB for some reason has it's own iif function which works like:
PHP Code:
$a 1;
echo 
iif(($a == 1), "a is one""a is not one"); // echoes "a is one" 
But you can just do this:
PHP Code:
$a 1;
echo (
$a == "a is one" "a is not one"); 
Also as a language construct it should be significantly faster than any user-defined function.


The other one is unnecessary ifs. Check this out:
PHP Code:
function stuff($s)
{
    if (
$s == 50)
    {
        return 
true;
    }
    else
    {
        return 
false;
    }

You can just do this:
PHP Code:
function stuff($s)
{
    return (
$s == 50);

Just sharing the goodness. I don't know why so few people know about these.
Reply With Quote
  #2  
Old 03-09-2003, 10:56 PM
p0wered p0wered is offline
 
Join Date: Mar 2003
Posts: 14
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I was searching similar instructions to develop that sequencer you were helping me with. Php.net is sometimes really hard to understand, because for many functions and stuff like the above do not have sufficient examples which will allow a new user like myself to understand completly the full capabilities of a function or other.
Reply With Quote
  #3  
Old 03-09-2003, 10:58 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

php.net is designed more as a reference, not a tutorial (although IMO it has the best docs I have ever used for any language). You should use a book instead to learn PHP. This book should rock, judging by I've used a book by the same title except it was for Javascript: http://www.sams.com/catalog/product....-CDF148BBB9A0}
Reply With Quote
  #4  
Old 03-09-2003, 11:07 PM
p0wered p0wered is offline
 
Join Date: Mar 2003
Posts: 14
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I go to php.net to 'refer' to the large library of functions in their functions list, I find it that since they made php, they would have everything, of which they do, stuff like boolean and whatnot cannot be found on online resources easily and books, well many people most of the time do not wish to invest in books that won't come in use later.

I for one have an amazing part-time job, and will be checking up on the book you had suggested, and on any others, but til they come, I am stuck with php.net, vB.org and Good ol' filburt You seem to know alot!
Reply With Quote
  #5  
Old 03-10-2003, 12:26 AM
Velocd's Avatar
Velocd Velocd is offline
 
Join Date: Mar 2002
Location: CA University
Posts: 1,696
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I've known about those two techniques, but have had little use for them considering how rarely I use "echo" (since everything is done by templates), and that if I ever make functions, I usually never think about using the comparison operator when returning.
Reply With Quote
  #6  
Old 03-10-2003, 11:59 AM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

well, i also know both, the last one is a really good thing i think.

the ?: structure is surely fast, but it makes the code a bit harder to read, so i don't think you should use it in hacks you provied
Reply With Quote
  #7  
Old 03-10-2003, 12:01 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Personally I don't think it's too hard to read but each to his own.
Reply With Quote
  #8  
Old 03-10-2003, 12:17 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

well, good proggers can read it without problems, but we learn in university not to use that kind of shourtcuts...
Reply With Quote
Reply


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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:17 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03932 seconds
  • Memory Usage 2,232KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete