Bizarre code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • derfy
    Senior Member
    • Jul 2005
    • 244
    • 3.8.x

    #16
    There is no iif() function built into php. However...

    Comment

    • TimIgoe
      New Member
      • Aug 2005
      • 14
      • 3.6.x

      #17
      Originally posted by derfy
      There is no iif() function built into php. However...

      http://www.phpit.net/code/iif-function
      But there is a build in ternary if

      $test = ($something > 0 ? 'true' : 'false');

      which is what the iif funciton is?!

      Comment

      • timnp
        Member
        • Sep 2007
        • 30

        #18
        Hi Derfy,

        What would be the point of writing a wrapper function for a build in core language feature? Why not just always use the language feature directly?

        Which of these is the best way to echo "Hello World"?

        PHP Code:
        function myAmazingEchoingFunction($text){
          echo 
        $text;
        }
        myAmazingEchoingFunction("Hello World"); 
        or

        PHP Code:
        echo "Hello World"
        ?

        Comment

        • Dilly
          Senior Member
          • Mar 2005
          • 1812

          #19
          It allows an optional second parameter, and simplifies the code reading for anyone who isn't a PHP guru.

          It's depreceated, which means they remove them as they come across them. They are causing bugger all slowdown, so it is a waste of resources to search through the code to replace them.

          Seriously guys, if we're going to nitpick, choose something worthwhile.

          Comment

          • timnp
            Member
            • Sep 2007
            • 30

            #20
            Hi Dilly,

            This raises a number of points. Firstly, I don't think that you have to be a PHP 'guru' to understand how if statements work. Secondly, I think that in order to read through the vBulletin code in the first place someone would have to be at least above a basic level of PHP understanding.

            Why do they remove it as they come across them? Why not just look for them and remove them?

            I know that just running this code or my stupid examples above won't cause any noticable slowdown or any significant load, but what about when there are a thousand or so users online, all posting because they're excited about the same thing. Every little bit of optimisation helps; I'm not saying that we should go through the code with a fine toothpick and spend months and months working out the best way to optimize various bits but there are many unoptimisations that seem to have been made in vBulletin for no justifiable reason what so ever.

            I think this example is a good one as it is called so many times throughout the rest of the code. Similarly, this isn't the only unoptimisation (see above rants), together they have a cumulative effect. The example is indicative of a much wider problem.

            Next. Why do we want a ternary if function that takes an optional third parameter? Why not just use the standard core if?

            Comment

            • timnp
              Member
              • Sep 2007
              • 30

              #21
              Maybe someone can explain something to me.

              Using vBulletin 3.7.0 beta 4 now.

              In the 'user' table the IP addresses are stored using dotted decimal format xxx.xxx.xxx.xxx , in the 'post' table it is the same.

              Why then, do we break from this tradition in the 'visitormessage' table and store them as converted decimal?

              192.168.0.9 becomes 3232235529 etc

              Comment

              Related Topics

              Collapse

              Working...