Serving the Quantitative Finance Community

 
User avatar
Cuchulainn
Topic Author
Posts: 23029
Joined: July 16th, 2004, 7:38 am

Handy, one-liner, rule-of-thumb, dos/donts in any language

July 8th, 2014, 6:58 am

Kick offR1: Many classes use plug-in methods/algorithms. Use lambda functions to configure them.
 
User avatar
rmax
Posts: 374
Joined: December 8th, 2005, 9:31 am

Handy, one-liner, rule-of-thumb, dos/donts in any language

July 8th, 2014, 7:08 am

R2 Exit a sub routine in one place only
 
User avatar
neuroguy
Posts: 0
Joined: February 22nd, 2011, 4:07 pm

Handy, one-liner, rule-of-thumb, dos/donts in any language

July 8th, 2014, 10:44 am

QuoteOriginally posted by: rmaxR2 Exit a sub routine in one place onlyIndeed.The other day I was brushing my teeth. My girlfried called me, so I left the room and went out to talk to her. She happened to come back to the bathroom with me and commented that I had left the tap running. I said that I had behaved like a routine with more that one exit point. She called me sad. I found it quite pleasing.R3 favour association over composition and composition over inheritance
 
User avatar
Cuchulainn
Topic Author
Posts: 23029
Joined: July 16th, 2004, 7:38 am

Handy, one-liner, rule-of-thumb, dos/donts in any language

July 8th, 2014, 10:54 am

QuoteR3 favour association over composition and composition over inheritance N:N better than 1:N better than 1:1? (brilliant R3, I'm gonna frame this one!)
Last edited by Cuchulainn on July 7th, 2014, 10:00 pm, edited 1 time in total.
 
User avatar
rmax
Posts: 374
Joined: December 8th, 2005, 9:31 am

Handy, one-liner, rule-of-thumb, dos/donts in any language

July 8th, 2014, 11:27 am

R4 When you say to yourself "I will kludge this in as it will be quicker" it NEVER EVER is. When you come back to use the code you will either (a) swear (b) rewrite it as you should have done initally.
 
User avatar
Traden4Alpha
Posts: 3300
Joined: September 20th, 2002, 8:30 pm

Handy, one-liner, rule-of-thumb, dos/donts in any language

July 8th, 2014, 12:06 pm

R5 floats, doubles, etc. are NOT real numbers (ints aren't integers, either)
 
User avatar
rmax
Posts: 374
Joined: December 8th, 2005, 9:31 am

Handy, one-liner, rule-of-thumb, dos/donts in any language

July 8th, 2014, 12:38 pm

QuoteOriginally posted by: Traden4AlphaR5 floats, doubles, etc. are NOT real numbers (ints aren't integers, either)Agree on floats and doubles etc. Nasty things.Integers are perfect and friendly though...surely....? What don't I know?
 
User avatar
Traden4Alpha
Posts: 3300
Joined: September 20th, 2002, 8:30 pm

Handy, one-liner, rule-of-thumb, dos/donts in any language

July 8th, 2014, 12:46 pm

QuoteOriginally posted by: rmaxQuoteOriginally posted by: Traden4AlphaR5 floats, doubles, etc. are NOT real numbers (ints aren't integers, either)Agree on floats and doubles etc. Nasty things.Integers are perfect and friendly though...surely....? What don't I know?Upper bounds! Actual integers can be arbitrarily large but ints and longs cannot. Sooner or later one will discover that adding 1 to an int or a long produces a very negative number.
Last edited by Traden4Alpha on July 7th, 2014, 10:00 pm, edited 1 time in total.
 
User avatar
Polter
Posts: 1
Joined: April 29th, 2008, 4:55 pm

Handy, one-liner, rule-of-thumb, dos/donts in any language

July 8th, 2014, 2:21 pm

Unsigned integers are a form of modular ring, all perfectly well-defined :-)OTOH, signed integers are... scary :-One of my personal favorites:R6. Minimize scope
 
User avatar
rmax
Posts: 374
Joined: December 8th, 2005, 9:31 am

Handy, one-liner, rule-of-thumb, dos/donts in any language

July 8th, 2014, 4:01 pm

QuoteOriginally posted by: Traden4AlphaQuoteOriginally posted by: rmaxQuoteOriginally posted by: Traden4AlphaR5 floats, doubles, etc. are NOT real numbers (ints aren't integers, either)Agree on floats and doubles etc. Nasty things.Integers are perfect and friendly though...surely....? What don't I know?Upper bounds! Actual integers can be arbitrarily large but ints and longs cannot. Sooner or later one will discover that adding 1 to an int or a long produces a very negative number.I remember as a yoof being interested that on a BBC Model B you could execute Call !-4 and that would perform a soft reset. I never understood it until I was older and realised of course that you were actually Calling &FFFC.
 
User avatar
Traden4Alpha
Posts: 3300
Joined: September 20th, 2002, 8:30 pm

Handy, one-liner, rule-of-thumb, dos/donts in any language

July 8th, 2014, 6:57 pm

QuoteOriginally posted by: rmaxQuoteOriginally posted by: Traden4AlphaQuoteOriginally posted by: rmaxQuoteOriginally posted by: Traden4AlphaR5 floats, doubles, etc. are NOT real numbers (ints aren't integers, either)Agree on floats and doubles etc. Nasty things.Integers are perfect and friendly though...surely....? What don't I know?Upper bounds! Actual integers can be arbitrarily large but ints and longs cannot. Sooner or later one will discover that adding 1 to an int or a long produces a very negative number.I remember as a yoof being interested that on a BBC Model B you could execute Call !-4 and that would perform a soft reset. I never understood it until I was older and realised of course that you were actually Calling &FFFC.Indeed! And that leads to:R7 Avoid really clever tricks that depend on quirks such as executing Call !-4 when you were actually Calling &FFFC.
 
User avatar
rmax
Posts: 374
Joined: December 8th, 2005, 9:31 am

Handy, one-liner, rule-of-thumb, dos/donts in any language

July 9th, 2014, 9:00 am

R8. You are not using recursion enough in the solution
 
User avatar
Cuchulainn
Topic Author
Posts: 23029
Joined: July 16th, 2004, 7:38 am

Handy, one-liner, rule-of-thumb, dos/donts in any language

July 9th, 2014, 9:18 am

R9: In order to get the real project estimate, multiply the developer's estimate by 3.
 
User avatar
daveangel
Posts: 5
Joined: October 20th, 2003, 4:05 pm

Handy, one-liner, rule-of-thumb, dos/donts in any language

July 9th, 2014, 9:32 am

QuoteOriginally posted by: rmaxR8. You are not using recursion enough in the solutiondoesn't this contradict R7 ?
knowledge comes, wisdom lingers
 
User avatar
neuroguy
Posts: 0
Joined: February 22nd, 2011, 4:07 pm

Handy, one-liner, rule-of-thumb, dos/donts in any language

July 9th, 2014, 11:05 am

QuoteOriginally posted by: daveangelQuoteOriginally posted by: rmaxR8. You are not using recursion enough in the solutiondoesn't this contradict R7 ?The perenial debate about recursion. I think that used correctly it can improve code. Used badly it just makes things more complex.Personally I think it is ok to use it where you are applying a simple atomic operation to a clean data-structure.In this case you get nicely condensed code where the intention should be clear by virtue of the target data structure.Its bad when it is unnecessary, or where the intention is difficult to understand. For example using it in calculations (without an accompanying datastructure) is dangerous and seldom if ever necessary (in my opinion).However I dont think it violates R7, which to my interpretation is making a statement about not utilising side-effects (either in a 'clever' or stupid manner - just don't do it!) By definition side effects are implicit and implementation specific. Utilising recursion properly should not automatically mean exploiting side effects. However it is a valid concern that recursive algorithms might encourage one to do so.