Coding: Fleeting Thoughts

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

Moderators: phlip, Moderators General, Prelates

User avatar
Aaeriele
Posts: 2127
Joined: Tue Feb 23, 2010 3:30 am UTC
Location: San Francisco, CA

Re: Coding: Fleeting Thoughts

Postby Aaeriele » Tue Mar 16, 2010 5:55 am UTC

|Erasmus| wrote:FT, or maybe more of a Rant:
I hate our revision control system and the stupidity that ensues around here because of it. It makes false guarantees about multiple changes not conflicting with other when submitted for integration by just not letting us submit multiple changes which edit the same file(s). So we constantly integrate things which break stuff because we try to test lots of 'non conflicting' changes at once on the same baseline, and we end up with ridiculous amounts of office politics as everyone tries to work out who gets to go next with regards to these conflicting changes. It doesn't help that the built in merge command is incapable of resolving any kind of difference automatically.

Really, I'm just sick of having to wait for other integrations, merge with the baseline, and then get harrassed to put my (untested on the current baseline) change up for integration quickly because otherwise people will block, or start getting on my managers case because it is now her 'turn' to get stuff tested/integrated and she hasn't put anything up in the last 5 seconds!

tl;dr. Fuck the workflow around here.


Out of curiosity, what VCS are you using?
Vaniver wrote:Harvard is a hedge fund that runs the most prestigious dating agency in the world, and incidentally employs famous scientists to do research.

afuzzyduck wrote:ITS MEANT TO BE FLUTTERSHY BUT I JUST SEE AAERIELE! CURSE YOU FORA!

|Erasmus|
Branson
Posts: 2643
Joined: Tue Oct 30, 2007 7:53 am UTC
Location: Sydney, Australia
Contact:

Re: Coding: Fleeting Thoughts

Postby |Erasmus| » Tue Mar 16, 2010 10:38 am UTC

Aegis.

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 Mar 16, 2010 12:28 pm UTC

|Erasmus| wrote:But commenting is amazingly powerful.

Code: Select all

int a;
// a is an integer.

You laugh now, but try reading something written in Perl without the help of inane comments like those.
<quintopia> You're not crazy. you're the goddamn headprogrammingspock!
<Weeks> You're the goddamn headprogrammingspock!
<Cheese> I love you

|Erasmus|
Branson
Posts: 2643
Joined: Tue Oct 30, 2007 7:53 am UTC
Location: Sydney, Australia
Contact:

Re: Coding: Fleeting Thoughts

Postby |Erasmus| » Tue Mar 16, 2010 12:48 pm UTC

headprogrammingczar wrote:
|Erasmus| wrote:But commenting is amazingly powerful.

Code: Select all

int a;
// a is an integer.

You laugh now, but try reading something written in Perl without the help of inane comments like those.

I imagine it may be useful in any number of duct typed or type inferred languages. Not C or Java, though.

User avatar
Aaeriele
Posts: 2127
Joined: Tue Feb 23, 2010 3:30 am UTC
Location: San Francisco, CA

Re: Coding: Fleeting Thoughts

Postby Aaeriele » Tue Mar 16, 2010 1:03 pm UTC

|Erasmus| wrote:Aegis.


Do you happen to know why it was chosen (and/or when it was chosen)? I'm guessing that it's somewhat of a legacy system which has simply managed to persist, since it doesn't seem like it would be an ideal choice given modern options (reading the User Guide for it, I see mention of "locking all files needed for a change, atomically", which literally makes me shudder, and seems to be the problem you were referring to...).
Vaniver wrote:Harvard is a hedge fund that runs the most prestigious dating agency in the world, and incidentally employs famous scientists to do research.

afuzzyduck wrote:ITS MEANT TO BE FLUTTERSHY BUT I JUST SEE AAERIELE! CURSE YOU FORA!

User avatar
Moo
Oh man! I'm going to be so rebellious! I'm gonna...
Posts: 6441
Joined: Thu Aug 16, 2007 3:15 pm UTC
Location: Beyond the goblin city
Contact:

Re: Coding: Fleeting Thoughts

Postby Moo » Tue Mar 16, 2010 4:25 pm UTC

I have my first technical interview in four years tomorrow, with Alexander Forbes. One hour C# programming test. EEEP.
Proverbs 9:7-8 wrote:Anyone who rebukes a mocker will get an insult in return. Anyone who corrects the wicked will get hurt. So don't bother correcting mockers; they will only hate you.
Hawknc wrote:FFT: I didn't realise Proverbs 9:7-8 was the first recorded instance of "haters gonna hate"

|Erasmus|
Branson
Posts: 2643
Joined: Tue Oct 30, 2007 7:53 am UTC
Location: Sydney, Australia
Contact:

Re: Coding: Fleeting Thoughts

Postby |Erasmus| » Tue Mar 16, 2010 11:43 pm UTC

Aaeriele wrote:
|Erasmus| wrote:Aegis.


Do you happen to know why it was chosen (and/or when it was chosen)? I'm guessing that it's somewhat of a legacy system which has simply managed to persist, since it doesn't seem like it would be an ideal choice given modern options (reading the User Guide for it, I see mention of "locking all files needed for a change, atomically", which literally makes me shudder, and seems to be the problem you were referring to...).

Indeed that is the the problem I am referring to. It doesn't make any real guarantees, and just gives us worlds of pain.

It is a legacy system as such. I do not know why it was chosen, which was well before my time (and hell, I've been here nearly 3 years now. I am starting to feel old, and I'm only 22).

Also, good luck Moo! I'm sure you'll be fine.

qbg
Posts: 586
Joined: Tue Dec 18, 2007 3:37 pm UTC

Re: Coding: Fleeting Thoughts

Postby qbg » Wed Mar 17, 2010 4:48 am UTC

LLVM & Clang sure do move fast; by the time I'm done compiling the updates to my checkout, the repository has been updated again!

User avatar
Pesto
Posts: 737
Joined: Wed Sep 05, 2007 5:33 pm UTC
Location: Berkeley, CA

Re: Coding: Fleeting Thoughts

Postby Pesto » Wed Mar 17, 2010 8:39 am UTC

Does anyone else sometimes feel like using recursion is cheating?

When I use it, I feel like I didn't actually have to do anything in the way of actual programming. Kind of like "if base case, else magic".

User avatar
e^iπ+1=0
Much, much better than Gooder
Posts: 2065
Joined: Sun Feb 15, 2009 9:41 am UTC
Location: Lancaster

Re: Coding: Fleeting Thoughts

Postby e^iπ+1=0 » Wed Mar 17, 2010 9:05 am UTC

Niklaus Wirth wrote:The power of recursion evidently lies in the possibility of defining an infinite set of objects by a finite statement. In the same manner, an infinite number of computations can be described by a finite recursive program, even if this program contains no explicit repetitions.
poxic wrote:You, sir, have heroic hair.
poxic wrote:I note that the hair is not slowing down. It appears to have progressed from heroic to rocking.

(Avatar by Sungura)

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

Re: Coding: Fleeting Thoughts

Postby headprogrammingczar » Wed Mar 17, 2010 1:15 pm UTC

Pesto wrote:Does anyone else sometimes feel like using recursion is cheating?

When I use it, I feel like I didn't actually have to do anything in the way of actual programming. Kind of like "if base case, else magic".

That's pretty much how all programming works, even sometimes in non-recursive code. Try writing a program in a functional language, and you will learn to appreciate the programming that goes into the "magic".
<quintopia> You're not crazy. you're the goddamn headprogrammingspock!
<Weeks> You're the goddamn headprogrammingspock!
<Cheese> I love you

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 » Wed Mar 17, 2010 1:17 pm UTC

Mathematical induction: also magic?
Sandry wrote:Bless you, Briareos.

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

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 » Wed Mar 17, 2010 2:43 pm UTC

Induction = Recursion, for some values of zen.
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
lulzfish
Posts: 1214
Joined: Tue Dec 16, 2008 8:17 am UTC

Re: Coding: Fleeting Thoughts

Postby lulzfish » Wed Mar 17, 2010 6:54 pm UTC

Pesto wrote:Does anyone else sometimes feel like using recursion is cheating?
When I use it, I feel like I didn't actually have to do anything in the way of actual programming. Kind of like "if base case, else magic".

No, but I feel like using Qt is cheating.
The most work I did for my music player was when Phonon fucked up and I had to glue together GStreamer and Qt.
It's like the whole project was sticking Legos together, but then I had to go get some K'nex because I needed a really long section and I ran out of Legos.

User avatar
Xeio
Friends, Faidites, Countrymen
Posts: 5101
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\
Contact:

Re: Coding: Fleeting Thoughts

Postby Xeio » Wed Mar 17, 2010 7:23 pm UTC

Pesto wrote:Does anyone else sometimes feel like using recursion is cheating?
On the plus side, you can effectively smash the magick with a large rock in adequate test cases (StackOverflowException, rawr).

Having that problem with one of the facebook puzzles (though, it seems my correct solutions are either too slow or too memory inefficient anyway, so I might try rewriting them in C++, not that that fixes the recursion problem).

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 » Wed Mar 17, 2010 7:23 pm UTC

lulzfish wrote:It's like the whole project was sticking Legos together, but then I had to go get some K'nex because I needed a really long section and I ran out of Legos.

I know what that's like, both figuratively and literally.

FT: I just went to edit one line of a ~3.2 kB stylesheet written about six months ago and ended up spending five minutes making sure that the properties are all vertically aligned. I still haven't changed that one line.
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
Briareos
Posts: 1940
Joined: Thu Jul 12, 2007 12:40 pm UTC
Location: Town of the Big House

Re: Coding: Fleeting Thoughts

Postby Briareos » Wed Mar 17, 2010 7:40 pm UTC

Xeio wrote:
Pesto wrote:Does anyone else sometimes feel like using recursion is cheating?
On the plus side, you can effectively smash the magick with a large rock in adequate test cases (StackOverflowException, rawr).

Having that problem with one of the facebook puzzles (though, it seems my correct solutions are either too slow or too memory inefficient anyway, so I might try rewriting them in C++, not that that fixes the recursion problem).
Might I recommend tail-call optimization? Also, ridiculous contortions to turn arbitrary function X into a tail-recursive one?
Sandry wrote:Bless you, Briareos.

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

User avatar
Pesto
Posts: 737
Joined: Wed Sep 05, 2007 5:33 pm UTC
Location: Berkeley, CA

Re: Coding: Fleeting Thoughts

Postby Pesto » Thu Mar 18, 2010 12:41 am UTC

Briareos wrote:Mathematical induction: also magic?

In the same respect, yes.

Edit: Although perhaps less so in the case of induction. There's actual work involved in a proof by induction. You have to solve two equations.

urobythos
Posts: 34
Joined: Thu Mar 11, 2010 3:55 am UTC
Location: 3 AM

Re: Coding: Fleeting Thoughts

Postby urobythos » Thu Mar 18, 2010 2:41 am UTC

not counting on Coding

Maelstrom.
Posts: 76
Joined: Tue Oct 21, 2008 12:18 pm UTC

Re: Coding: Fleeting Thoughts

Postby Maelstrom. » Thu Mar 18, 2010 4:52 am UTC

I was testing an email script I was writing at work. Its job was to read in some data, line by line, and send off an email based upon each line. Usually only one line in this file will be used for the actual email sending, the other lines being extra junk. It just so happens that I had made a small mistake with the end of file checking in my file loop. The result was an infinite loop, with the last line of the file being a valid, email producing line. Which was read in and processed multiple times before I noticed the error.

A few thousand emails later, I have very definitely learned my lesson.

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 » Thu Mar 18, 2010 5:31 am UTC

Ah yes, the classic infinite email loop. As a newly hired employee I once managed to send about 20k emails to all the top directors/executives in the space of a few seconds, subject: "Oh me yarm!", body: "Lollercopter". It's times like these where it pays off to have ninja IT gnome skills and access.
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
Aaeriele
Posts: 2127
Joined: Tue Feb 23, 2010 3:30 am UTC
Location: San Francisco, CA

Re: Coding: Fleeting Thoughts

Postby Aaeriele » Thu Mar 18, 2010 5:37 am UTC

Is it bad that I've actually done that intentionally before? Not maliciously, but because my boss told me "we need to try and track down a weird issue occurring when a mailbox has a ton of emails in it - can you figure out a way to get us such a mailbox to test on?"

With his blessing, I successfully created a mailbox with around ~2GB worth of emails (across a few tens of thousands of messages).
Vaniver wrote:Harvard is a hedge fund that runs the most prestigious dating agency in the world, and incidentally employs famous scientists to do research.

afuzzyduck wrote:ITS MEANT TO BE FLUTTERSHY BUT I JUST SEE AAERIELE! CURSE YOU FORA!

User avatar
RoadieRich
The Black Hand
Posts: 1037
Joined: Tue Feb 12, 2008 11:40 am UTC
Location: Behind you

Re: Coding: Fleeting Thoughts

Postby RoadieRich » Thu Mar 18, 2010 6:34 am UTC

Aaeriele wrote:Is it bad that I've actually done that intentionally before? Not maliciously, but because my boss told me "we need to try and track down a weird issue occurring when a mailbox has a ton of emails in it - can you figure out a way to get us such a mailbox to test on?"

With his blessing, I successfully created a mailbox with around ~2GB worth of emails (across a few tens of thousands of messages).


Was that a case of, "I'll loop it n-thousand times, should be enough" or "'shout when it's big enough', ^C"?
73, de KE8BSL loc EN26.

User avatar
Josephine
Posts: 2142
Joined: Wed Apr 08, 2009 5:53 am UTC

Re: Coding: Fleeting Thoughts

Postby Josephine » Thu Mar 18, 2010 8:07 am UTC

Moo wrote:I have my first technical interview in four years tomorrow, with Alexander Forbes. One hour C# programming test. EEEP.

How'd that go?
Belial wrote:Listen, what I'm saying is that he committed a felony with a zoo animal.

User avatar
Moo
Oh man! I'm going to be so rebellious! I'm gonna...
Posts: 6441
Joined: Thu Aug 16, 2007 3:15 pm UTC
Location: Beyond the goblin city
Contact:

Re: Coding: Fleeting Thoughts

Postby Moo » Thu Mar 18, 2010 8:35 am UTC

Hey, thanks for asking. It went OK.

The questions were dead easy, embarrassingly so actually. Q1: write the first 30 terms of the Fibonacci sequence to the console (with a recap of Fib). Q2: Quicksort these names (with a recap of how Quicksort works). Q3: create these OO classes (hint: use inheritance).
But it was in a really noisy office on a buggy computer though so I didn't finish :-/ Hopefully the code that's there is good enough for a call-back.

Got a two hour one tomorrow at another company (testing C#, SQL, HTML, JavaScript, XML/XSD). It's like university all over again, bah.
Proverbs 9:7-8 wrote:Anyone who rebukes a mocker will get an insult in return. Anyone who corrects the wicked will get hurt. So don't bother correcting mockers; they will only hate you.
Hawknc wrote:FFT: I didn't realise Proverbs 9:7-8 was the first recorded instance of "haters gonna hate"

User avatar
Josephine
Posts: 2142
Joined: Wed Apr 08, 2009 5:53 am UTC

Re: Coding: Fleeting Thoughts

Postby Josephine » Thu Mar 18, 2010 8:37 am UTC

ah, okay. Wow, those are dead easy. I wonder what the next place will ask.
Belial wrote:Listen, what I'm saying is that he committed a felony with a zoo animal.

User avatar
Moo
Oh man! I'm going to be so rebellious! I'm gonna...
Posts: 6441
Joined: Thu Aug 16, 2007 3:15 pm UTC
Location: Beyond the goblin city
Contact:

Re: Coding: Fleeting Thoughts

Postby Moo » Thu Mar 18, 2010 8:49 am UTC

Update: just got a call from the recruiter, they want to see me on Tuesday.
Proverbs 9:7-8 wrote:Anyone who rebukes a mocker will get an insult in return. Anyone who corrects the wicked will get hurt. So don't bother correcting mockers; they will only hate you.
Hawknc wrote:FFT: I didn't realise Proverbs 9:7-8 was the first recorded instance of "haters gonna hate"

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 » Thu Mar 18, 2010 9:33 am UTC

I cannot decide if this is good code or not:

Code: Select all

Map<String, WorkUnitParam> result = new HashMap<String, WorkUnitParam>();

outer:
for (Map.Entry<String, String> entry : paramNameMap.entrySet()) {
  for (Map<String, WorkUnitParam> map : new Map[]{argParams, rwParams, roParams, defaultParams}) {
    WorkUnitParam param = map.get(entry.getKey());
    if (param == null) {
      continue;
    }
    result.put(entry.getValue(), param);
    continue outer;
  }
}

return result;
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
headprogrammingczar
Posts: 3072
Joined: Mon Oct 22, 2007 5:28 pm UTC
Location: Beaming you up

Re: Coding: Fleeting Thoughts

Postby headprogrammingczar » Thu Mar 18, 2010 12:45 pm UTC

Without any comments, I can't figure out what it is doing, so I would have to go with 'no'. If it had comments, I might put it in the realm of magic and dragons, unless it turns out the loop is doing something completely mundane.
<quintopia> You're not crazy. you're the goddamn headprogrammingspock!
<Weeks> You're the goddamn headprogrammingspock!
<Cheese> I love you

User avatar
Link
Posts: 1419
Joined: Sat Mar 07, 2009 11:33 am UTC
Location: ᘝᓄᘈᖉᐣ
Contact:

Re: Coding: Fleeting Thoughts

Postby Link » Thu Mar 18, 2010 12:51 pm UTC

Looks confusing, but if it works, I guess it's OK. It would be a lot better with tuples and tuple expansion à-la Python, though.

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 » Thu Mar 18, 2010 1:07 pm UTC

It takes a Map<String, String> and four Map<String, Foo>s to a Map<String, Foo> by looking up each key in the Map<String, String> in the four maps and putting the Foo in the result with the corresponding value as key. The four maps have to be checked in order.

In Haskell:

Code: Select all

-- Assuming the four Map String Foos are in scope
magicFunction :: Map String String -> Map String Foo
magicFunction = fromList . concatMap lookupMap . toList
  where lookupMap (from, to) | isNothing val = []
                             | otherwise = [(to, fromJust val)]
          where val = fromFirst . mconcat . map First . map (lookup from) $ [argParams, rwParams, roParams, defaultParams]
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
Aaeriele
Posts: 2127
Joined: Tue Feb 23, 2010 3:30 am UTC
Location: San Francisco, CA

Re: Coding: Fleeting Thoughts

Postby Aaeriele » Thu Mar 18, 2010 1:16 pm UTC

RoadieRich wrote:
Aaeriele wrote:Is it bad that I've actually done that intentionally before? Not maliciously, but because my boss told me "we need to try and track down a weird issue occurring when a mailbox has a ton of emails in it - can you figure out a way to get us such a mailbox to test on?"

With his blessing, I successfully created a mailbox with around ~2GB worth of emails (across a few tens of thousands of messages).


Was that a case of, "I'll loop it n-thousand times, should be enough" or "'shout when it's big enough', ^C"?


Sort of a combination; I knew the approximate size of the message being sent, so knew about how much would be enough, but was sitting around to ^C just in case.
Vaniver wrote:Harvard is a hedge fund that runs the most prestigious dating agency in the world, and incidentally employs famous scientists to do research.

afuzzyduck wrote:ITS MEANT TO BE FLUTTERSHY BUT I JUST SEE AAERIELE! CURSE YOU FORA!

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 » Thu Mar 18, 2010 10:30 pm UTC

I'd say that the

Code: Select all

if (param == null) continue;
stuff;
should be rewritten as:

Code: Select all

if (param != null)
{
  stuff;
}

The pattern in the first one I guess is good if you have a lot of checks... and just want to have lots of small if(bad)continue; blocks rather than a bunch of nested if(good) blocks... but for just one test, it just hampers readability.

Also, I'd probably use "break" rather than "continue outer" for the other one, but that's just me.

Code: Select all

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

fazzone
Posts: 186
Joined: Wed Dec 10, 2008 9:38 pm UTC
Location: A boat

Re: Coding: Fleeting Thoughts

Postby fazzone » Thu Mar 18, 2010 10:54 pm UTC

phlip wrote:Also, I'd probably use "break" rather than "continue outer" for the other one, but that's just me.


Would that work? I could be wrong, but wouldn't using a break mean that the initial for loop does not start again? In other words, wouldn't using a break jump past the inner loop's closing brace, after which the next iteration of the outer for loop would take place? Whereas, the continue outer causes the outer loop to start again entirely, does it not? I've never even seen labeled continue statements in Java before (never knew they existed either), but that seems to me like what would happen.
*/

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 » Thu Mar 18, 2010 11:51 pm UTC

No, continue just makes a loop start again with its next value:

Code: Select all

for (int i = 0; i < 3; i++)
{
  System.out.println("Start " + i);
  if (i == 1) continue;
  System.out.println("End " + i);
}

Code: Select all

Start 0
End 0
Start 1
Start 2
End 2


That same result would be outputted by both:

Code: Select all

outer: for (int i = 0; i < 3; i++)
{
  inner: {
    System.out.println("Start " + i);
    if (i == 1) continue outer;
    System.out.println("End " + i);
  }
}

Code: Select all

outer: for (int i = 0; i < 3; i++)
{
  inner: {
    System.out.println("Start " + i);
    if (i == 1) break inner;
    System.out.println("End " + i);
  }
}

Code: Select all

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

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 » Fri Mar 19, 2010 2:01 am UTC

I'm a bad person and I should feel bad...
Spoiler:

Code: Select all

<!--
  Nested brackets aren't regular :(
  This'll check for nested parens and braces up to 3 deep... after that, you're on your own.
  bracketRegex 0 = ".*"
  bracketRegex n = "(?:[^(){}]|\\(" ++ bracketRegex (n - 1) ++ "\\)|\\{" ++ bracketRegex (n - 1) ++ "\\})*"
-->
<validation message="Brackets must be entered in pairs" field="companyName" type="regex">(?:[^(){}]|\((?:[^(){}]|\((?:[^(){}]|\(.*\)|\{.*\})*\)|\{(?:[^(){}]|\(.*\)|\{.*\})*\})*\)|\{(?:[^(){}]|\((?:[^(){}]|\(.*\)|\{.*\})*\)|\{(?:[^(){}]|\(.*\)|\{.*\})*\})*\})*</validation>


(XML format changed to protect the innocent and to be more self-explanatory.)

Code: Select all

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

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 Mar 19, 2010 5:11 am UTC

phlip wrote:I'd say that the

Code: Select all

if (param == null) continue;
stuff;
should be rewritten as:

Code: Select all

if (param != null)
{
  stuff;
}

The pattern in the first one I guess is good if you have a lot of checks... and just want to have lots of small if(bad)continue; blocks rather than a bunch of nested if(good) blocks... but for just one test, it just hampers readability.

Also, I'd probably use "break" rather than "continue outer" for the other one, but that's just me.

Indeed, that's what I ended up doing. That is what code looks like when it's been grown organically for some time, there being lots of checks at one point, and there being stuff after the inner loop in case it fell through (nothing found).
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.

itaibn
Posts: 142
Joined: Mon Dec 29, 2008 7:06 pm UTC

Re: Coding: Fleeting Thoughts

Postby itaibn » Fri Mar 19, 2010 6:34 am UTC

I was this close to finding the Ultimate Question. :cry:

Code: Select all

>>> 0x2b or not 0x2b
43
I NEVER use all-caps.

User avatar
chridd
Has a vermicelli title
Posts: 846
Joined: Tue Aug 19, 2008 10:07 am UTC
Location: ...Earth, I guess?
Contact:

Re: Coding: Fleeting Thoughts

Postby chridd » Fri Mar 19, 2010 11:41 pm UTC

itaibn wrote:I was this close to finding the Ultimate Question. :cry:

Code: Select all

>>> 0x2b or not 0x2b
43

Code: Select all

>>> 0x2a or not 0x2a
42
To A or not to A... that is the real question!
~ chri d. d. /tʃɹɪ.di.di/ (Phonotactics, schmphonotactics) · she · Forum game scores
mittfh wrote:I wish this post was very quotable...

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

Re: Coding: Fleeting Thoughts

Postby hotaru » Fri Mar 19, 2010 11:54 pm UTC

itaibn wrote:I was this close to finding the Ultimate Question. :cry:

Code: Select all

>>> 0x2b or not 0x2b
43

just add a double negative at the beginning...

Code: Select all

>>> ~-0x2b or not 0x2b
42

Code: Select all

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


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 14 guests