Page 44 of 251

Re: Coding: Fleeting Thoughts

Posted: Tue Mar 16, 2010 5:55 am UTC
by Aaeriele
|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?

Re: Coding: Fleeting Thoughts

Posted: Tue Mar 16, 2010 10:38 am UTC
by |Erasmus|
Aegis.

Re: Coding: Fleeting Thoughts

Posted: Tue Mar 16, 2010 12:28 pm UTC
by headprogrammingczar
|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.

Re: Coding: Fleeting Thoughts

Posted: Tue Mar 16, 2010 12:48 pm UTC
by |Erasmus|
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.

Re: Coding: Fleeting Thoughts

Posted: Tue Mar 16, 2010 1:03 pm UTC
by Aaeriele
|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...).

Re: Coding: Fleeting Thoughts

Posted: Tue Mar 16, 2010 4:25 pm UTC
by Moo
I have my first technical interview in four years tomorrow, with Alexander Forbes. One hour C# programming test. EEEP.

Re: Coding: Fleeting Thoughts

Posted: Tue Mar 16, 2010 11:43 pm UTC
by |Erasmus|
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.

Re: Coding: Fleeting Thoughts

Posted: Wed Mar 17, 2010 4:48 am UTC
by qbg
LLVM & Clang sure do move fast; by the time I'm done compiling the updates to my checkout, the repository has been updated again!

Re: Coding: Fleeting Thoughts

Posted: Wed Mar 17, 2010 8:39 am UTC
by Pesto
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".

Re: Coding: Fleeting Thoughts

Posted: Wed Mar 17, 2010 9:05 am UTC
by e^iπ+1=0
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.

Re: Coding: Fleeting Thoughts

Posted: Wed Mar 17, 2010 1:15 pm UTC
by headprogrammingczar
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".

Re: Coding: Fleeting Thoughts

Posted: Wed Mar 17, 2010 1:17 pm UTC
by Briareos
Mathematical induction: also magic?

Re: Coding: Fleeting Thoughts

Posted: Wed Mar 17, 2010 2:43 pm UTC
by Berengal
Induction = Recursion, for some values of zen.

Re: Coding: Fleeting Thoughts

Posted: Wed Mar 17, 2010 6:54 pm UTC
by lulzfish
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.

Re: Coding: Fleeting Thoughts

Posted: Wed Mar 17, 2010 7:23 pm UTC
by Xeio
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).

Re: Coding: Fleeting Thoughts

Posted: Wed Mar 17, 2010 7:23 pm UTC
by TheChewanater
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.

Re: Coding: Fleeting Thoughts

Posted: Wed Mar 17, 2010 7:40 pm UTC
by Briareos
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?

Re: Coding: Fleeting Thoughts

Posted: Thu Mar 18, 2010 12:41 am UTC
by Pesto
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.

Re: Coding: Fleeting Thoughts

Posted: Thu Mar 18, 2010 2:41 am UTC
by urobythos
not counting on Coding

Re: Coding: Fleeting Thoughts

Posted: Thu Mar 18, 2010 4:52 am UTC
by Maelstrom.
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.

Re: Coding: Fleeting Thoughts

Posted: Thu Mar 18, 2010 5:31 am UTC
by Berengal
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.

Re: Coding: Fleeting Thoughts

Posted: Thu Mar 18, 2010 5:37 am UTC
by Aaeriele
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).

Re: Coding: Fleeting Thoughts

Posted: Thu Mar 18, 2010 6:34 am UTC
by RoadieRich
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"?

Re: Coding: Fleeting Thoughts

Posted: Thu Mar 18, 2010 8:07 am UTC
by Josephine
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?

Re: Coding: Fleeting Thoughts

Posted: Thu Mar 18, 2010 8:35 am UTC
by Moo
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.

Re: Coding: Fleeting Thoughts

Posted: Thu Mar 18, 2010 8:37 am UTC
by Josephine
ah, okay. Wow, those are dead easy. I wonder what the next place will ask.

Re: Coding: Fleeting Thoughts

Posted: Thu Mar 18, 2010 8:49 am UTC
by Moo
Update: just got a call from the recruiter, they want to see me on Tuesday.

Re: Coding: Fleeting Thoughts

Posted: Thu Mar 18, 2010 9:33 am UTC
by Berengal
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;

Re: Coding: Fleeting Thoughts

Posted: Thu Mar 18, 2010 12:45 pm UTC
by headprogrammingczar
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.

Re: Coding: Fleeting Thoughts

Posted: Thu Mar 18, 2010 12:51 pm UTC
by Link
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.

Re: Coding: Fleeting Thoughts

Posted: Thu Mar 18, 2010 1:07 pm UTC
by Berengal
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]

Re: Coding: Fleeting Thoughts

Posted: Thu Mar 18, 2010 1:16 pm UTC
by Aaeriele
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.

Re: Coding: Fleeting Thoughts

Posted: Thu Mar 18, 2010 10:30 pm UTC
by phlip
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.

Re: Coding: Fleeting Thoughts

Posted: Thu Mar 18, 2010 10:54 pm UTC
by fazzone
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.

Re: Coding: Fleeting Thoughts

Posted: Thu Mar 18, 2010 11:51 pm UTC
by phlip
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);
  }
}

Re: Coding: Fleeting Thoughts

Posted: Fri Mar 19, 2010 2:01 am UTC
by phlip
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.)

Re: Coding: Fleeting Thoughts

Posted: Fri Mar 19, 2010 5:11 am UTC
by Berengal
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).

Re: Coding: Fleeting Thoughts

Posted: Fri Mar 19, 2010 6:34 am UTC
by itaibn
I was this close to finding the Ultimate Question. :cry:

Code: Select all

>>> 0x2b or not 0x2b
43

Re: Coding: Fleeting Thoughts

Posted: Fri Mar 19, 2010 11:41 pm UTC
by chridd
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!

Re: Coding: Fleeting Thoughts

Posted: Fri Mar 19, 2010 11:54 pm UTC
by hotaru
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