Open Side Menu Go to the Top

08-06-2012 , 05:19 PM
Yeah.. I guess you don't need to encrypt the whole volume. I just do because it seems easier to me--largely because I do a terrible job of organizing my data.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
08-06-2012 , 06:49 PM
which do you use/prefer and why?

Code:
func()
{
   if (condition)
   {
      code1
   }
   else
   {
      code2
   }
}
or

Code:
func()
{
   if (!condition)
   {
      code2
      return
   }

   code1
}
ive always done the first, but ive switched to second and code seems cleaner and easier to read
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-06-2012 , 06:54 PM
I thought negative conditions are harder to maintain and more prone to being screwed up if the condition is modified?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-06-2012 , 06:56 PM
it depends

Last edited by anononon; 08-06-2012 at 06:56 PM. Reason: i often use negative checks though
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-06-2012 , 07:11 PM
I think it depends on how I think of it. If I think of something as a special case with a special return value, then I would just use if a return. Otherwise, I think else is clearer.

I really try to avoid having big functions that have a long split in control flow, though.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-06-2012 , 07:55 PM
In general I'll do an early return from an abnormal/error condition.

Otherwise I won't unless it really bloats things up to do it "the right way."

Last edited by Neil S; 08-06-2012 at 07:55 PM. Reason: Or if I forget. :)
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-06-2012 , 07:55 PM
Quote:
Originally Posted by kerowo
I thought negative conditions are harder to maintain and more prone to being screwed up if the condition is modified?
i mean i guess you can just test the positive condition and then return, just the same, just depends on how you think of your variable

Quote:
Originally Posted by NoahSD
I really try to avoid having big functions that have a long split in control flow, though.
how do you work around it?

Quote:
Originally Posted by Neil S
In general I'll do an early return from an abnormal/error condition.

Otherwise I won't unless it really bloats things up to do it "the right way."
yeah this is pretty much the purpose

Code:
func()
{
   if (!condition_normally_true)
   {
      handle code
      return
   }
   normal expected code
}
as opposed to putting the expected code in an else block
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-06-2012 , 08:26 PM
I like #2 but it might be a platform related answer. In node it's super standard and considered a best practice to pass an error in as the first argument of a function.

In my brain I naturally think "first in, first out", so it makes a lot more sense to exit early when I can. There's a lot of good variable names where both evaluating to true or false makes just about equal sense, and you can pick other names that make sense when trying to evaluate to false instead of true.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-06-2012 , 08:33 PM
Quote:
In my brain I naturally think "first in, first out", so it makes a lot more sense to exit early when I can...
This is a good way to put it; it's how I feel about it.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-06-2012 , 09:13 PM
Quote:
Originally Posted by greg nice

how do you work around it?
refactor the long code blocks into their own functions, so the if and the else both have a single line of code that invokes the refactored function. not doing this is really bad imo if the code blocks have more than about 5 lines.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-06-2012 , 09:18 PM
yeah, you don't want to have a situation where you have a 10+ line if block in the middle of your controller or logic, that quickly turns into a procedural mess of garbage
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-06-2012 , 09:24 PM
Spoiler:
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-06-2012 , 09:24 PM
Quote:
Originally Posted by greg nice
Code:
func()
{
   if (!condition_normally_true)
   {
      handle code
      return
   }
   normal expected code
}
This.

Juk
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-06-2012 , 09:25 PM
s/spaces/tabs/
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-06-2012 , 09:30 PM
Yeah.. either refactor into separate functions or think about a way to let the two blocks share more code.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-06-2012 , 09:37 PM
Quote:
Originally Posted by kyleb
Spoiler:
absolutely false

tabs are the worst
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-06-2012 , 09:38 PM
spaces ftw.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-06-2012 , 09:41 PM
Quote:
Originally Posted by kyleb
yeah, you don't want to have a situation where you have a 10+ line if block in the middle of your controller or logic, that quickly turns into a procedural mess of garbage
i'm guilty of this, sometimes when i break things into too many functions i feel like its a waste of time. its as if i feel more comfortable just scrolling down the page to see the progression instead of having to jump back and forth to different function locations in the file or in another file
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-06-2012 , 09:43 PM
there are images for spaces and tabs on that site, for the record

they're agnostic; they have insulting pictures towards all paradigms

ETA: as for breaking things into functions, the TDD zealots would say it's important to have for testing purposes. there's a healthy balance between having 500 functions and 1000 lines of code and 10 functions and 1000 lines of code, though - the balance is between as you noted
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-06-2012 , 10:23 PM
If there's one thing Lisp got right, it is there is no such thing as if-else syntax. Just the fact that people go around in circles over this stuff is proof enough of how horrendous "else" is.

At least in Python, I find I always always have to check to make sure I ~don't~ need an else statement to be sure that I don't get that one stupid bug leaking around that happens because I accidentally allowed code fall-through. This forces me to stop coding, write a bunch of stupid tests, and then figure out if "else" is really needed at all. Considering "if" is such an important part of programming, I can't help but think that this is a massive time-sink and (pun?) constricts my process.

I just try to use "else" as little as possible.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-06-2012 , 10:32 PM
Pretty cool talk by Rich Hickey that he gave at RailsConf 2012.

http://www.youtube.com/watch?v=rI8tNMsozo0

There's apparently an expanded version. I sort of don't want to blow through an hour and half watching it. The RailsConf talk got me thinking about a whole slew of stuff and got me to really research ORM. Now that I have seen and read all the opinions, and then though really hard about how it would work in my application and what may happen in the future, I think all the naysayers of ORM hit the nail on the head: may be great right now, but woah to your future.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-06-2012 , 10:45 PM


LOL
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-06-2012 , 10:59 PM
Quote:
Originally Posted by greg nice
i'm guilty of this, sometimes when i break things into too many functions i feel like its a waste of time. its as if i feel more comfortable just scrolling down the page to see the progression instead of having to jump back and forth to different function locations in the file or in another file
get a better editor or learn how to use your current one better
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-07-2012 , 02:13 AM
yea yea yea ill learn vim one day
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
08-07-2012 , 02:24 AM
Quote:
Originally Posted by greg nice
yea yea yea ill learn vim one day
no day but today

also vim is awesome; stop wasting your life in other editors.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

      
m