Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
nested if-statements V.S. multiple-alternative if-statements V.S. switch
Old 08-05-2011, 10:38 PM Re: nested if-statements V.S. multiple-alternative if-statements V.S. switch
Lashtal's Avatar
wherenomanhasgonebefore

Posts: 680
Name: Lashtal
Trades: 0
Quote:
Originally Posted by Physicsguy View Post
Is there a website online to reliably test code like this, or any code at all? It would be nice to have a one-stop, go-to source for code benchmarking, where all other benchmarks would reside and be based off of.
Exactly my thought as of a week ago. Structured like Stack-Overflow, but for running instances of these routines and comparing results with others in a scientific manner.

Then it dawned on me: NO

Why not?

...i'm sure someone else will do it eventually, especially given the popularity of open-source. But then I realized, I happen to agree with Bill Gates a little more: http://upload.wikimedia.org/wikipedi..._Hobbyists.jpg


I believe people in the tech-market need to stop giving away their sh*t for free, it can make not only your own, but others' efforts amount to $0

and yes: while $$$ isn't the only reason we code, it's a nice incentive.

Overall: I think we need to stop being stupid, to stop throwing our money away. To stop devaluing our technical SKILLS


That very idea right there: while being highly-contributive to the world of comp. sci. *could* do that.

I mean: is there a reason for why or why not Microsoft conceals source code for Windows 7? Competitive Advantage, maybe? What do you think?


it's generally understood in the programming industry that a great deal of techies lack business sense.
__________________
Currently Reading:
Please login or register to view this content. Registration is FREE
Lashtal is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-07-2011, 08:40 PM Re: nested if-statements V.S. multiple-alternative if-statements V.S. switch
King Spam Talker

Posts: 1,110
Name: Paul W
Trades: 0
Quote:
Originally Posted by Physicsguy View Post
Is there a website online to reliably test code like this, or any code at all? It would be nice to have a one-stop, go-to source for code benchmarking, where all other benchmarks would reside and be based off of.
There are various sets of benchmarks floating around but most are specific to compiler (and version)+language+host and don't sufficiently split those components.

As to general program performance, most large bodies of code have plenty of room fro optomisation without attempting to squeeze a bit out of if statements - and if you're that desperate then it's time to recode in assembler anyway.

Use switch for discrete values - that's what it's designed for. I personally use nested if/elses as I think it makes compound conditionals clearer and code more maintainable.

Just for a laugh I'll quote some code that a certain agency delivered a little while ago to a premier league football club - see if you can think how to optimise it

Code:
connect to (Oracle) db
select all first team players by id  (premier key)
disconnect from db
 
for each id
    connect to db
    select player details
    disconnect from db
end-for
And this cutting-edge agency was being paid a six figure sum.
__________________
Great music:
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Old 08-08-2011, 11:32 AM Re: nested if-statements V.S. multiple-alternative if-statements V.S. switch
chrishirst's Avatar
Defies a Status

Posts: 44,046
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0


I should think a first year DBA could do better than that.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 08-08-2011, 05:58 PM Re: nested if-statements V.S. multiple-alternative if-statements V.S. switch
Lashtal's Avatar
wherenomanhasgonebefore

Posts: 680
Name: Lashtal
Trades: 0
Discrete and Continuous Data (for those seeking a defintion)

likewise: switch is only useful for types int and char, not type double.


(can switch be used for string manipulation in any language?)
__________________
Currently Reading:
Please login or register to view this content. Registration is FREE
Lashtal is offline
Reply With Quote
View Public Profile
 
Old 08-08-2011, 06:52 PM Re: nested if-statements V.S. multiple-alternative if-statements V.S. switch
NullPointer's Avatar
Will Code for Food

Posts: 2,883
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by Lashtal View Post
(can switch be used for string manipulation in any language?)
PHP. As far as I know any type can be used in a switch statement in PHP (except for resources like db connections and file pointers maybe?).

Quote:
Originally Posted by Lashtal View Post
likewise: switch is only useful for types int and char, not type double.
Just to clarify, there are issues that can crop up when comparing floats in general. I don't know if any language explicitly prevents you from using a float in a switch, it just might not be a good idea to do it, depending on how the value is calculated.

Maybe Paul can clarify, but I think what he meant was discrete sets of values. Technically any data stored on a computer is discrete, including floats.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 08-08-2011, 07:41 PM Re: nested if-statements V.S. multiple-alternative if-statements V.S. switch
Lashtal's Avatar
wherenomanhasgonebefore

Posts: 680
Name: Lashtal
Trades: 0
Quote:
Originally Posted by NullPointer View Post
...more often than not, good design leads to good performance.
true.dat

---

your if's were executing faster than your switches, as PHP-tech doesn't handles switches well... according to those guys from that link I supplied earlier.
__________________
Currently Reading:
Please login or register to view this content. Registration is FREE
Lashtal is offline
Reply With Quote
View Public Profile
 
Old 08-10-2011, 07:14 PM Re: nested if-statements V.S. multiple-alternative if-statements V.S. switch
King Spam Talker

Posts: 1,110
Name: Paul W
Trades: 0
Quote:
Originally Posted by NullPointer View Post
PHP. As far as I know any type can be used in a switch statement in PHP (except for resources like db connections and file pointers maybe?).



Just to clarify, there are issues that can crop up when comparing floats in general. I don't know if any language explicitly prevents you from using a float in a switch, it just might not be a good idea to do it, depending on how the value is calculated.

Maybe Paul can clarify, but I think what he meant was discrete sets of values. Technically any data stored on a computer is discrete, including floats.
I was indeed. And you're right - compare floats for exact value at your own peril.

Lashtal asks: can switch be used for string manipulation in any language? Simple answer is "it depends on the manipulation required". I can remember writing my first form-data-parsing code, in C, using a switch. 1996 was a good year

By the way, you can theoretically use handles of any description in php switches but it's a meaningless exercise as php doesn't guarantee any characteristic other than nominal for handles.
__________________
Great music:
Please login or register to view this content. Registration is FREE



Please login or register to view this content. Registration is FREE

Last edited by PaulW; 08-10-2011 at 07:18 PM..
PaulW is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to nested if-statements V.S. multiple-alternative if-statements V.S. switch

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.21051 seconds with 10 queries