Coding: Fleeting Thoughts

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

User avatar
mister_m
Posts: 34
Joined: Fri Feb 04, 2011 2:51 am UTC

Re: Coding: Fleeting Thoughts

Postby mister_m » Fri Feb 04, 2011 2:57 am UTC

Does anyone have any tips on writing absolutely bulletproof test cases? I'm a lowly intern, and my boss is having me automate some user interface testing with this thing called Selenium (http://seleniumhq.org/) in C# with nunit. I've done a little bit of testing in Java at school but I'd like to make sure I get stuff right. Any tips would be welcome if you have them.

nowfocus
Posts: 948
Joined: Wed Apr 09, 2008 1:34 am UTC

Re: Coding: Fleeting Thoughts

Postby nowfocus » Fri Feb 04, 2011 3:34 am UTC

Dason wrote:
nowfocus wrote:Honestly, R is free, and better in almost every conceivable way, but for some reason Economics just choose STATA, and now everyone uses it so everyone uses it.

Hell yeah R!

I've never used STATA so I can't comment on it really. I've wanted to give it a try to just see what would cause somebody to use it but I'm not going to pay for a copy and the university doesn't support it so it looks like I don't get to try it out.

Full Disclosure: I've been using R for 6 years, STATA for maybe 1.

Bottom line: don't use STATA unless you have too, and you'll know if you have too. The only reason I use it is that Economists have programmed certain methods into it, and not R.

Some of the major issues I've had today
- No multiple databases: You 'load' a dataset, and then you can't have a second one, or just go along your happy way defining new variables
- Speed: I'm finding it quite slow
- RAM management: STATA needs a continuous block of RAM allocated at the start of the program. This means it can't pull all the RAM you have on your computer, so large calculations that should run on your hardware don't. My school computer has over 3 gigs of RAM, and I can only allocate 700m to STATA. You may not be aware of how R does this, and that's because R does it properly. It takes RAM when it needs it without nagging the user, and it doesn't need to be a continuous block.
- "Matrix Size": STATA works on this internal matrix where it stores everything, which trades off number of variables and sample size. Problem is that it doesn't update the size of this matrix as you add variables. So, I could have set my matrix size as 300, but all of a sudden it needs 350 to run a command. The command fails, asking you for a larger matrix size. Why it can't allocate itself a larger matrix on its own is beyond me.
- Syntax Checking: Beyond generally useless errors, STATA only checks your syntax as it needs it. So, if I misspecified a post estimation option, it first runs the large calculation for 10 minutes, then checks what the post estimation options are, then throws an error without returning results. The obvious solution here is to check the syntax before the big calculation so I can change it before I waste my time
- Catergorical variable handling: STATA doesn't have the ability to store a variable as catergorical. What is has to do is break the variable out into n-1 dummy variables, and store each of these in RAM. I have to store several hundred of these variables because of this, making the RAM issues worse.
- No capital letters: makes code much less readable, as thefirstone is harder to read than theFirstOne.

Those are the things that have been making life difficult most days. There are others but these are the most glaring/common.

My advice: Stay far, far away unless you plan on doing Econometrics. If you do, then do everything you can in R and bring in STATA for the final estimation.
Jahoclave wrote:Besides if you observe romance, you change the outcome. Especially if you put his/her friend Catherine in a box.

Menacing Spike wrote:Was it the copper hammer or the children part that caused censoring?

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Coding: Fleeting Thoughts

Postby Berengal » Fri Feb 04, 2011 6:30 pm UTC

mister_m wrote:Does anyone have any tips on writing absolutely bulletproof test cases? I'm a lowly intern, and my boss is having me automate some user interface testing with this thing called Selenium (http://seleniumhq.org/) in C# with nunit. I've done a little bit of testing in Java at school but I'd like to make sure I get stuff right. Any tips would be welcome if you have them.

The only way to write bulletproof code is not to. By extension, the only way to write bulletproof test cases is not to. Really, tests can only prove the presence of bugs, not the absence, so "bulletproof tests" is a bit of an oxymoron.

That said, the only thing you can do is basically "test everything". There is no golden hammer or silver bullet. Indeed, there's not even a chrome plated frying pan. Just get a list of features and write a test for each one. Features can usually be identified by <form> and <a> tags in the html, or things that otherwise can be submitted or looked up using a browser. Also possibly useful are use-cases or stories. There might already be some for the project but you can make up your own by pretending you're a user.
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

User avatar
Area Man
Posts: 256
Joined: Thu Dec 25, 2008 8:08 pm UTC
Location: Local

Re: Coding: Fleeting Thoughts

Postby Area Man » Tue Feb 08, 2011 5:40 am UTC

joshz wrote:I don't really get all the Java hate, tbh. I mean, it's a little slow since the jvm has to run, but other than that, why is it that bad?


There are many reasons for my distaste for java, it could fill essay of it's own, but today I'll keep it succinct: it sucks worse than PHP.
Bisquick boxes are a dead medium.

User avatar
Emu*
Posts: 689
Joined: Mon Apr 28, 2008 9:47 am UTC
Location: Cardiff, UK
Contact:

Re: Coding: Fleeting Thoughts

Postby Emu* » Tue Feb 08, 2011 11:47 am UTC

That's a pretty small reason to put Java below PHP.

At least Java uses namespaces properly.
Cosmologicon wrote:Emu* implemented a naive east-first strategy and ran it for an hour, producing results that rivaled many sophisticated strategies, visiting 614 cells. For this, Emu* is awarded Best Deterministic Algorithm!

User avatar
headprogrammingczar
Posts: 3072
Joined: Mon Oct 22, 2007 5:28 pm UTC
Location: Beaming you up

Re: Coding: Fleeting Thoughts

Postby headprogrammingczar » Tue Feb 08, 2011 1:35 pm UTC

Not to mention, PHP has the same bug.
<quintopia> You're not crazy. you're the goddamn headprogrammingspock!
<Weeks> You're the goddamn headprogrammingspock!
<Cheese> I love you

User avatar
TheChewanater
Posts: 1279
Joined: Sat Aug 08, 2009 5:24 am UTC
Location: lol why am I still wearing a Santa suit?

Re: Coding: Fleeting Thoughts

Postby TheChewanater » Tue Feb 08, 2011 1:40 pm UTC

I'm pretty sure that PHP doesn't support multiple threads, so that might be more of a problem.

I wonder if this is a library bug or the result of copy/paste coding.
ImageImage
http://internetometer.com/give/4279
No one can agree how to count how many types of people there are. You could ask two people and get 10 different answers.

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6598
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Tue Feb 08, 2011 1:46 pm UTC

It's a code problem, probably copy pasted from some example somewhere by both the PHP and Java devs. You can see the patch for the Java bug here:

http://bugs.openjdk.java.net/show_bug.cgi?id=100119

I'm sure if you do some searching, you can find the patch for the PHP bug.
Summum ius, summa iniuria.

User avatar
Area Man
Posts: 256
Joined: Thu Dec 25, 2008 8:08 pm UTC
Location: Local

Re: Coding: Fleeting Thoughts

Postby Area Man » Tue Feb 08, 2011 1:50 pm UTC

PHP found and fixed the problem earlier, this bug was found thanks to it. And for PHP it was only on 32 bit systems - so it didn't affect us (at work) at all.
ed. except for that one windows server... :roll:
Bisquick boxes are a dead medium.

User avatar
Rippy
Posts: 2101
Joined: Sun Jul 22, 2007 11:27 pm UTC
Location: Ontario, Can o' Duh

Re: Coding: Fleeting Thoughts

Postby Rippy » Thu Feb 10, 2011 6:35 pm UTC

Is there an easy way in Haskell to create a type that accepts a range of values? I'm keeping track of lots of integer values from 0-100, it'd be much easier to have something like

Code: Select all

data Int = 0 | 1 | ... | 99 | 100

than to check bounds myself all the time.

User avatar
headprogrammingczar
Posts: 3072
Joined: Mon Oct 22, 2007 5:28 pm UTC
Location: Beaming you up

Re: Coding: Fleeting Thoughts

Postby headprogrammingczar » Thu Feb 10, 2011 7:13 pm UTC

You can make a newtype around Int, and give it your own Num instance. The key function will be fromIntegral.
<quintopia> You're not crazy. you're the goddamn headprogrammingspock!
<Weeks> You're the goddamn headprogrammingspock!
<Cheese> I love you

User avatar
TheChewanater
Posts: 1279
Joined: Sat Aug 08, 2009 5:24 am UTC
Location: lol why am I still wearing a Santa suit?

Re: Coding: Fleeting Thoughts

Postby TheChewanater » Thu Feb 10, 2011 9:10 pm UTC

FT:

Code: Select all

>>>from math import *
>>>
 n = 0.739085
>>> n
0.73908499999999999
>>> cos(n)
0.73908522295048873
>>> acos(n)
0.73908533097758233


Mind = blown.
ImageImage
http://internetometer.com/give/4279
No one can agree how to count how many types of people there are. You could ask two people and get 10 different answers.

User avatar
Rippy
Posts: 2101
Joined: Sun Jul 22, 2007 11:27 pm UTC
Location: Ontario, Can o' Duh

Re: Coding: Fleeting Thoughts

Postby Rippy » Thu Feb 10, 2011 9:12 pm UTC

Got something close with this:
Spoiler:

Code: Select all

newtype StatVal = StatVal Int
                  deriving (Eq, Show)
instance Num StatVal where
    StatVal v1 + StatVal v2 = StatVal (if v1+v2 > 100 then 100 else v1+v2)
    StatVal v1 - StatVal v2 = StatVal (if v1-v2 < 0   then 0   else v1-v2)
    StatVal v1 * StatVal v2 = StatVal (if v1*v2 > 100 then 100 else v1*v2)
    abs (StatVal v) = StatVal v
    signum (StatVal v) = StatVal v
    fromInteger = StatVal . fromInteger

It works for arithmetic, but you can still define, say, "StatVal (-10)" just fine. I have a feeling my instance is awful anyway >_>

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Thu Feb 10, 2011 9:24 pm UTC

TheChewanater wrote:FT:

Code: Select all

>>>from math import *
>>>
 n = 0.739085
>>> n
0.73908499999999999
>>> cos(n)
0.73908522295048873
>>> acos(n)
0.73908533097758233


Mind = blown.


http://www.wolframalpha.com/input/?i=so ... 28x%29%3Dx
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

letterX
Posts: 535
Joined: Fri Feb 22, 2008 4:00 am UTC
Location: Ithaca, NY

Re: Coding: Fleeting Thoughts

Postby letterX » Thu Feb 10, 2011 9:41 pm UTC

You, sir, name? wrote:
TheChewanater wrote:FT:

Code: Select all

>>>from math import *
>>>
 n = 0.739085
>>> n
0.73908499999999999
>>> cos(n)
0.73908522295048873
>>> acos(n)
0.73908533097758233


Mind = blown.


http://www.wolframalpha.com/input/?i=so ... 28x%29%3Dx


Not to be glib*, but this is pretty much identical to

Code: Select all

>>> from math import *
>>> n = 1
>>> n
1
>>> n ** 2
1
>>> sqrt(n)
1.0


Mind = blown.


* I lied, I'm totally being glib

User avatar
Briareos
Posts: 1940
Joined: Thu Jul 12, 2007 12:40 pm UTC
Location: Town of the Big House

Re: Coding: Fleeting Thoughts

Postby Briareos » Thu Feb 10, 2011 9:50 pm UTC

Rippy wrote:Got something close with this:
Spoiler:

Code: Select all

newtype StatVal = StatVal Int
                  deriving (Eq, Show)
instance Num StatVal where
    StatVal v1 + StatVal v2 = StatVal (if v1+v2 > 100 then 100 else v1+v2)
    StatVal v1 - StatVal v2 = StatVal (if v1-v2 < 0   then 0   else v1-v2)
    StatVal v1 * StatVal v2 = StatVal (if v1*v2 > 100 then 100 else v1*v2)
    abs (StatVal v) = StatVal v
    signum (StatVal v) = StatVal v
    fromInteger = StatVal . fromInteger

It works for arithmetic, but you can still define, say, "StatVal (-10)" just fine. I have a feeling my instance is awful anyway >_>
Why not

Code: Select all

fromInteger n | n < 0 = StatVal 0
              | n > 100 = StatVal 100
              | otherwise = StatVal $ fromInteger n
(I can't remember the exact syntax.)
Sandry wrote:Bless you, Briareos.

Blriaraisghaasghoasufdpt.
Oregonaut wrote:Briareos is my new bestest friend.

User avatar
headprogrammingczar
Posts: 3072
Joined: Mon Oct 22, 2007 5:28 pm UTC
Location: Beaming you up

Re: Coding: Fleeting Thoughts

Postby headprogrammingczar » Thu Feb 10, 2011 11:28 pm UTC

or

Code: Select all

fromInteger n
  | n < 0 = fromInteger (n + 100)
  | n >= 100 = frominteger (n - 100)
  | otherwise = StatVal n
<quintopia> You're not crazy. you're the goddamn headprogrammingspock!
<Weeks> You're the goddamn headprogrammingspock!
<Cheese> I love you

User avatar
TheChewanater
Posts: 1279
Joined: Sat Aug 08, 2009 5:24 am UTC
Location: lol why am I still wearing a Santa suit?

Re: Coding: Fleeting Thoughts

Postby TheChewanater » Fri Feb 11, 2011 3:42 am UTC

letterX wrote:Not to be glib*, but this is pretty much identical to

Code: Select all

>>> from math import *
>>> n = 1
>>> n
1
>>> n ** 2
1
>>> sqrt(n)
1.0


Mind = blown.


* I lied, I'm totally being glib

No, because any gradeschooler knows what the multiplicative identity is...
ImageImage
http://internetometer.com/give/4279
No one can agree how to count how many types of people there are. You could ask two people and get 10 different answers.

User avatar
jaap
Posts: 2094
Joined: Fri Jul 06, 2007 7:06 am UTC
Contact:

Re: Coding: Fleeting Thoughts

Postby jaap » Fri Feb 11, 2011 6:19 am UTC

Is it really that mindblowing that there is a number n such that n=cos(n)?
A look at the graphs of y=cos(x) and of y=x should make you realise it isn't.

Once you have that, it logically follows that acos(n) = acos(cos(n)) = n.

(Well, actually that is only true within an interval such as [0,pi) over which cos has a unique inverse given by acos.)

letterX
Posts: 535
Joined: Fri Feb 22, 2008 4:00 am UTC
Location: Ithaca, NY

Re: Coding: Fleeting Thoughts

Postby letterX » Fri Feb 11, 2011 7:06 am UTC

TheChewanater wrote:
letterX wrote:Not to be glib*, but this is pretty much identical to

Code: Select all

>>> from math import *
>>> n = 1
>>> n
1
>>> n ** 2
1
>>> sqrt(n)
1.0


Mind = blown.


* I lied, I'm totally being glib

No, because any gradeschooler knows what the multiplicative identity is...

Not my point. x^2 is below y = x before x = 1, and above it after. Same thing with cos(x).

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Coding: Fleeting Thoughts

Postby Berengal » Fri Feb 11, 2011 8:51 am UTC

Just thought I'd share what I'm working on with you. Properly anonymized by removing everything except code structure.

Code: Select all

public void foo() throws Exception {

    //
    ;
    ;
    ;
    ;
    ;

    ;
    ;

    ;
    ;
    ;

    ;

    while () {
      ;
      ;
      ;
      ;
      ;
      ;
      ;
      ;

      ;
      ;

      ;
      ;
      ;
      ;
      ;

      ;
      ;

      ;

      ;
      ;

      if () {
        ;
      }

      ;
      ;
      ;

      //
      ;
      ;

      if () {
        if ( && ) {
          ;
          try {
            ;
            ;
            ;
            ;
            ;
            ;
            ;

          } catch () {
            ;
          }
          if () {
            ;
            ;
            ;
            ;
            ;
            ;
            ;
          }
        }

        if () {
          while ( &&  &&  && ) {

            if ( &&  && ) {
              ;
              ;
              ;
              ;
              ;
              ;

              try {
                ;
                ;
                ;
                ;
                ;
                try {
                  ;
                } catch () {
                  ;
                }
                ;
                ;
                ;
                ;
                ;

              } catch () {
                ;
              }

              if () {
                ;
              } else {
                if () {
                  ;
                }
              }
            } else if ( &&  &&  &&  && ) {
              ;
              ;
              ;
              ;
              ;
              ;
              ;
              ;
              try {
                ;
              } catch () {
                ;
              }
              ;
              ;
              ;
              ;
              if () {
                ;
              } else {
                if () {
                  ;
                }
              }
            } else {
              ;
            }
          } //
        }


        if ( && ) {
          ;
        }
        if (( ||  || ) && ) {
          if () {
           
            ;
            if () {
              ;
            } else {
              ;
              if () {
                ;
              } else {
                ;
                if () {
                  ;
                } else {
                  ;
                }
              }
            }
          } else {
            ;
          }
        }

        if () {

          ;
          ;
          ;
          ;
        } else if ( ||  ||  ||
                    ) {
          ;
        } else {
          ;
         
          ;


          if () {
            ;
            ;
            if () {
              ;
            }
            if ( && ) {
              ;
            }
          }

          ;
          if () {
            ;
          }
          ;

          ;
          ;

          if () {
            if ( &&  && ) {
              if () {
                ;
                //
                ;
                //
              } else if () {
                ;
              } else if () {
                ;
              } else {
                ;
                if ( || ) {
                  ;
                }
              }
            } else if (
                &&
                && (( && )
                    || ( && ))) {
              if ( || ( && )) {
                ;
                if ( || ) {
                  ;
                }
              } else if () {//
                ;
                if ( || ) {
                  ;
                }
              }
            } else if ( && ) {
              if ( && ( ||  || )) {
                ;
                if ( || ) {
                  ;
                }
              } else if ( &&  && ) {
                if (( && )) {
                  ;
                } else if () {
                  ;
                }
              }
            }
          }
        }
      } else {
        ;
        ;
      }
      ;
      if () {
        ;
      }
      ;
    }
    if () {
      ;
    }
    ;
  }


"Woah, it looks like they wrote the entire program in one huge function!" you say. I wish they did. There's more of these.
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

User avatar
hotaru
Posts: 1045
Joined: Fri Apr 13, 2007 6:54 pm UTC

Re: Coding: Fleeting Thoughts

Postby hotaru » Fri Feb 11, 2011 1:30 pm UTC

Berengal wrote:"Woah, it looks like they wrote the entire program in one huge function!" you say. I wish they did. There's more of these.

it could be worse...

Code: Select all

factorial product enumFromTo 1
isPrime n 
factorial (1) `mod== 1

User avatar
headprogrammingczar
Posts: 3072
Joined: Mon Oct 22, 2007 5:28 pm UTC
Location: Beaming you up

Re: Coding: Fleeting Thoughts

Postby headprogrammingczar » Fri Feb 11, 2011 1:47 pm UTC

That's perl. It doesn't count. :D
<quintopia> You're not crazy. you're the goddamn headprogrammingspock!
<Weeks> You're the goddamn headprogrammingspock!
<Cheese> I love you

User avatar
Rippy
Posts: 2101
Joined: Sun Jul 22, 2007 11:27 pm UTC
Location: Ontario, Can o' Duh

Re: Coding: Fleeting Thoughts

Postby Rippy » Fri Feb 11, 2011 6:44 pm UTC

Changing fromInteger still doesn't change the type constructor though, so "StatVal (-10)" still gives you -10. It takes something like "fromInteger (-10) :: StatVal", which is clunky.

I ended up writing a wrapper function, statVal :: Int -> StatVal, which checks bounds and then creates the type. The upside is that this factors out code nicely; the downside is that you have to use that function name when creating the type. I don't think I actually will need to manually construct the type though, so it should be okay like this.

Spoiler:

Code: Select all

newtype StatVal = SV Int
    deriving (Eq, Ord, Show)

statVal :: Int -> StatVal
statVal x | x < 0     = SV 0
          | x > 100   = SV 100
          | otherwise = SV x

instance Num StatVal where
    SV v1 + SV v2 = statVal (v1+v2)
    SV v1 - SV v2 = statVal (v1-v2)
    SV v1 * SV v2 = statVal (v1*v2)
    negate v      = v
    abs v         = v
    signum 0      = 0
    signum _      = 1
    fromInteger i = statVal $ fromInteger i

gorcee
Posts: 1501
Joined: Sun Jul 13, 2008 3:14 am UTC

Re: Coding: Fleeting Thoughts

Postby gorcee » Fri Feb 11, 2011 9:40 pm UTC

TheChewanater wrote:FT:

Code: Select all

>>>from math import *
>>>
 n = 0.739085
>>> n
0.73908499999999999
>>> cos(n)
0.73908522295048873
>>> acos(n)
0.73908533097758233


Mind = blown.


What of it? The inaccuracies?

User avatar
Briareos
Posts: 1940
Joined: Thu Jul 12, 2007 12:40 pm UTC
Location: Town of the Big House

Re: Coding: Fleeting Thoughts

Postby Briareos » Fri Feb 11, 2011 9:53 pm UTC

Rippy wrote:I ended up writing a wrapper function, statVal :: Int -> StatVal, which checks bounds and then creates the type. The upside is that this factors out code nicely; the downside is that you have to use that function name when creating the type. I don't think I actually will need to manually construct the type though, so it should be okay like this.
I think that's the usual idea. Put all that in its own module, and don't export the actual type constructor.
Sandry wrote:Bless you, Briareos.

Blriaraisghaasghoasufdpt.
Oregonaut wrote:Briareos is my new bestest friend.

User avatar
phlip
Restorer of Worlds
Posts: 7573
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Coding: Fleeting Thoughts

Postby phlip » Sat Feb 12, 2011 1:42 am UTC

Rippy wrote:Changing fromInteger still doesn't change the type constructor though, so "StatVal (-10)" still gives you -10. It takes something like "fromInteger (-10) :: StatVal", which is clunky.

fromInteger is magic, though... once you've defined an instance of Num, it's simply "-10 :: StatVal", or just "-10" if it can infer the type... and it will automatically run it through fromInteger. That's what the required "fromInteger" and "fromRational" functions are for - decoding literals into any Num or Fractional instance - "17 :: SomeType" is just sugar for "fromInteger 17 :: SomeType", and "1.7 :: SomeType" is "fromRational (17 % 10) :: SomeType".

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

User avatar
headprogrammingczar
Posts: 3072
Joined: Mon Oct 22, 2007 5:28 pm UTC
Location: Beaming you up

Re: Coding: Fleeting Thoughts

Postby headprogrammingczar » Sat Feb 12, 2011 2:13 am UTC

Indeed. On freenode/#haskell, lambdabot has a Num instance for functions, where fromIntegral x _ = x. Combine with monadic style for wacky fun!

Code: Select all

> do {1; 2; 3; 4} 5
  4
<quintopia> You're not crazy. you're the goddamn headprogrammingspock!
<Weeks> You're the goddamn headprogrammingspock!
<Cheese> I love you

User avatar
TheChewanater
Posts: 1279
Joined: Sat Aug 08, 2009 5:24 am UTC
Location: lol why am I still wearing a Santa suit?

Re: Coding: Fleeting Thoughts

Postby TheChewanater » Sat Feb 12, 2011 2:48 am UTC

gorcee wrote:
TheChewanater wrote:FT:

Code: Select all

>>>from math import *
>>>
 n = 0.739085
>>> n
0.73908499999999999
>>> cos(n)
0.73908522295048873
>>> acos(n)
0.73908533097758233


Mind = blown.


What of it? The inaccuracies?

No, of the fact that there is a number n where n = cos(n) = acos(n). Although, it seems to be common knowledge to everyone else here...
ImageImage
http://internetometer.com/give/4279
No one can agree how to count how many types of people there are. You could ask two people and get 10 different answers.

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Sat Feb 12, 2011 2:55 am UTC

TheChewanater wrote:
gorcee wrote:
TheChewanater wrote:FT:

Code: Select all

>>>from math import *
>>>
 n = 0.739085
>>> n
0.73908499999999999
>>> cos(n)
0.73908522295048873
>>> acos(n)
0.73908533097758233


Mind = blown.


What of it? The inaccuracies?

No, of the fact that there is a number n where n = cos(n) = acos(n). Although, it seems to be common knowledge to everyone else here...


plot
f(x) = x
g(x) = cos(x)

If you can find a point where two meet, that is, where f(x) = g(x), then there is such a point that x = cos(x). And by extension acos(x) = acos(cos(x)) = x.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
GrawSith
Posts: 91
Joined: Fri Dec 28, 2007 2:46 pm UTC
Location: Down-frickin'-under.
Contact:

Re: Coding: Fleeting Thoughts

Postby GrawSith » Sat Feb 12, 2011 8:04 am UTC

Currently wanting to learn a new language. After four years of hobby-coding in Python & Ruby, it's a little stale for me. Right now I'm split between trying functional programming (Erlang or Haskell), or going back in time and trying pure C (after years of "this = that", explicitly setting my own memory seems ... intriguing.

User avatar
headprogrammingczar
Posts: 3072
Joined: Mon Oct 22, 2007 5:28 pm UTC
Location: Beaming you up

Re: Coding: Fleeting Thoughts

Postby headprogrammingczar » Sat Feb 12, 2011 12:56 pm UTC

I suggest Haskell or Erlang, since you will learn C in regular classes.
<quintopia> You're not crazy. you're the goddamn headprogrammingspock!
<Weeks> You're the goddamn headprogrammingspock!
<Cheese> I love you

Windowlicker
Posts: 323
Joined: Wed Dec 23, 2009 6:57 pm UTC
Location: St Andrews, Scotland

Re: Coding: Fleeting Thoughts

Postby Windowlicker » Sat Feb 12, 2011 11:40 pm UTC

What's the convention for naming multiple loop variables/counters (in separate loops)?

For example, if I use

Code: Select all

void bar(){
   for(int i=0; i<1000; i++)
      //code
   for(int i=0; i<6; i++)
      //other code
}


would it be frowned upon? I mean I think the scope for each of them is clear enough...
(I do realise that while typing this I can't think of any reason at all not to think of another name for the second loop, but I'm just curious)

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6598
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Sat Feb 12, 2011 11:46 pm UTC

No reason not to just use i, unless you think a more descriptive name will make the code more clear. With nested loops, convention is to go i, j, k:

Code: Select all

for (int i=0; i<1000; i++) {
    for (int j=0; j<1000; j++) {
        //code
    }
}


I have also seen people use i, ii, iii.

Code: Select all

for (int i=0; i<1000; i++) {
    for (int ii=0; ii<1000; ii++) {
        //code
    }
}
Summum ius, summa iniuria.

Windowlicker
Posts: 323
Joined: Wed Dec 23, 2009 6:57 pm UTC
Location: St Andrews, Scotland

Re: Coding: Fleeting Thoughts

Postby Windowlicker » Sat Feb 12, 2011 11:55 pm UTC

Alright, cheers. I tend to enjoy habits, moving away from basing it at i is.. a large amount of effort. I've never seen the ii, iii thing before.. I quite like that. I'll give it a go.

On a slightly (entirely) unrelated note, how do web devs these days write their (x)html? I've seen a lot of advice on forums around the internet advising away from Dreamweaver, but one of my lecturers spent much of a lecture the other day telling us that manually typing html died out ages ago and all the "pros" use graphical tools like Dreamweaver.
I'm inclined to go with the forums, partly because when I used Dreamweaver it didn't seem very good, and partly because that particular lecturer doesn't seem to actually know about any of the things he talks about..

User avatar
Rippy
Posts: 2101
Joined: Sun Jul 22, 2007 11:27 pm UTC
Location: Ontario, Can o' Duh

Re: Coding: Fleeting Thoughts

Postby Rippy » Sun Feb 13, 2011 12:03 am UTC

GrawSith wrote:Currently wanting to learn a new language. After four years of hobby-coding in Python & Ruby, it's a little stale for me. Right now I'm split between trying functional programming (Erlang or Haskell), or going back in time and trying pure C (after years of "this = that", explicitly setting my own memory seems ... intriguing.

Currently hobby coding in Haskell, so I'm biased, but I'd recommend it. Functional programming is really quite different, learning one can be frustrating because of that but it's really awesome in a lot of ways once you get over that. That said, low-level C programming is fun too.

Windowlicker wrote:What's the convention for naming multiple loop variables/counters (in separate loops)?

For example, if I use

Code: Select all

void bar(){
   for(int i=0; i<1000; i++)
      //code
   for(int i=0; i<6; i++)
      //other code
}


would it be frowned upon? I mean I think the scope for each of them is clear enough...
(I do realise that while typing this I can't think of any reason at all not to think of another name for the second loop, but I'm just curious)

Arbitrary variable names like that are supposed to be re-used. If you ask me, using a different arbitrary name in the 2nd loop would be confusing. The scope is plenty clear, and making the second one a 'j' just makes my brain think there's a reason they're named different, so if I weren't looking closely I'd think they were nested.



Now for my question.. (I will likely be plaguing this thread with Haskell questions for awhile). I'm trying to write a function to produce a [partly] randomly generated instance of a data type. So my thought was something like

Code: Select all

randomObj :: IO Obj
randomObj = do a <- randomRIO (0,10)
               return Obj (foo a) 0 --foo converts an int to the appropriate type

But this gives me errors. The function's trying to return Obj not IO Obj, and foo is being passed an IO Int rather than an Int. I'm out of ideas as to how to go about this.

Goddamn Haskell type system, I can appreciate your elegance and yet I can't yet totally make sense of you >_>.

User avatar
joshz
Posts: 1466
Joined: Tue Nov 11, 2008 2:51 am UTC
Location: Pittsburgh, PA

Re: Coding: Fleeting Thoughts

Postby joshz » Sun Feb 13, 2011 12:04 am UTC

That ii thing would kind of annoy me if I saw it in code, tbh. i j k is a pretty established standard, and having to count the number of "i"s would quickly get impractical.
You, sir, name? wrote:If you have over 26 levels of nesting, you've got bigger problems ... than variable naming.
suffer-cait wrote:it might also be interesting to note here that i don't like 5 fingers. they feel too bulky.

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Coding: Fleeting Thoughts

Postby You, sir, name? » Sun Feb 13, 2011 12:22 am UTC

Naming arbitrary variables by their consecutive position in the alphabet is mathematical convention. If you have a variable r, and you need another one, you name it s (unless there's some outstanding reason not to).

Starting with 'i' makes sense if you're just doing general iteration.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
Dason
Posts: 1311
Joined: Wed Dec 02, 2009 7:06 am UTC
Location: ~/

Re: Coding: Fleeting Thoughts

Postby Dason » Sun Feb 13, 2011 12:26 am UTC

There seem to be a few cases where using the preceding letter is more conventional. When dealing with arrays I typically think of a one dimensional array with n elements whereas a 2 dimensional array has dimensions n by m.
double epsilon = -.0000001;

User avatar
Thesh
Made to Fuck Dinosaurs
Posts: 6598
Joined: Tue Jan 12, 2010 1:55 am UTC
Location: Colorado

Re: Coding: Fleeting Thoughts

Postby Thesh » Sun Feb 13, 2011 12:33 am UTC

joshz wrote:That ii thing would kind of annoy me if I saw it in code, tbh. i j k is a pretty established standard, and having to count the number of "i"s would quickly get impractical.


But consecutive letters in impractical if you have over 26 levels of nesting...

Personally, I do i, j, k for three level nesting. I didn't have a problem reading i, ii, iii but if you started to go beyond three levels of nesting it would be illegible.
Summum ius, summa iniuria.


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 6 guests