The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
Is this proper coding?
Can someone tell me in their opinion if this is proper coding? The following code is the fix for the division by zero error.
I am replacing this: Code:
if ($totalthreads == 0) { $totalthreads = 1; } if ($totalposts == 0) { $totalposts = 1; } With this: Code:
$totalthreads == 0 ? $totalthreads = 1 : $totalthreads; $totalposts == 0 ? $totalposts = 1 : $totalposts; It works, but I am curious as to what your feelings are as to whether this is actually a proper way to do it or not. Can anyone tell I got bored enough to do this? |
#2
|
||||
|
||||
No opinions one way or the other?
|
#3
|
||||
|
||||
I don't know which is better. When I 'read' code, I like it better the first way - it just looks cleaner to me.
|
#4
|
||||
|
||||
I agree somewhat that it is easier to understand what the code in the first example is doing. But I also like the second way as it condenses 8 lines into 2.
|
#5
|
||||
|
||||
For single 'actions' to a condition, I actually like it like this:
PHP Code:
|
#6
|
||||
|
||||
Yes, that would be the better way to do it for single actions. I think I will use that instead of my way since I don't really need the else part of it for this particular code. Thanks for pointing that out.
I guess I'm just used to the brackets being there. |
#7
|
||||
|
||||
I can trump that.
PHP Code:
PHP Code:
|
#8
|
||||
|
||||
Quote:
Code:
if ($vbulletin->options['something_here'] == '') $comma_separated = '0'; |
#9
|
||||
|
||||
Quote:
nice thread , thanks boofo |
#10
|
||||
|
||||
Quote:
if it takes one or more additional cycles to process it? maybe. But it's php after all, so the uber-performance isn't that of an issue. max is a mathematic function which returns the greater value of the given params. If you don't want to have a number which is negative or equal to 0, you use max($n, 1) so you guarantee that you always have at least 1. Not sure about the performance, It's possible that the php engine uses the native c math function, so this might even speed things up a bit? dunno but then again, doesn't really matter :P Just intended to brag with my mad php skillz, honestly I think the idea itself is an issue here (it throws an error when it's zero? well, just increase it then. <- wtf?) If you really want to get help, you should explain your problem instead of the solution PHP Code:
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|