|
My co-worker came to me today asking how he could make it a compile time error to access an element in a map via operator[]() for when that element didn't exist in the map. He explained the bigger problem to me like this: "I want to be able to be like map[blah] or whatever but the problem is that if there's no entry for blah then it will insert an invalid pointer into my map!" I told him to check if blah exists in the map before trying to access map[blah]. He actually laughed at me and told me that would be ludicrous. He is currently trying to figure out how to write a "smart" pointer that will throw an exception when default constructed as a replacement for putting bare pointers in a map.
|
# ? May 21, 2010 20:53 |
|
|
# ? May 14, 2024 13:21 |
|
Lexical Unit posted:My co-worker came to me today asking how he could make it a compile time error to access an element in a map via operator[]() for when that element didn't exist in the map. Where do you work at?
|
# ? May 21, 2010 20:57 |
|
Your tax dollars at work folks (if you're American that is).
|
# ? May 21, 2010 20:58 |
|
Lexical Unit posted:My co-worker came to me today asking how he could make it a compile time error to access an element in a map via operator[]() for when that element didn't exist in the map. Has he ever written error handling in any of his code?
|
# ? May 21, 2010 21:00 |
|
lumberjack4 posted:Has he ever written error handling in any of his code?
|
# ? May 21, 2010 21:00 |
|
Lexical Unit posted:Your tax dollars at work folks (if you're American that is). Can I work there? I promise I won't ask retarded questions about hash maps.
|
# ? May 21, 2010 21:58 |
|
No sorry there's a currently a hiring freeze in effect. I'm afraid you'll have to go ask non-retarded questions elsewhere for now.
|
# ? May 21, 2010 22:00 |
|
Ah well, worth a shot. I'm the only one left after the last round of layoffs so there's no one left to ask non-retarded questions.
|
# ? May 21, 2010 22:18 |
|
Lexical Unit posted:hiring freeze BigRedDot fucked around with this message at 23:34 on May 21, 2010 |
# ? May 21, 2010 23:31 |
|
Lexical Unit fucked around with this message at 23:16 on Mar 4, 2020 |
# ? May 21, 2010 23:40 |
|
Lexical Unit posted:Run-time map nonsense I probably wouldn't be able to do the same amount of work, but certainly no less. I take up less room and ask 94% less stupid questions. Please consider my CV attached. ========== Resume.wpd
|
# ? May 22, 2010 08:21 |
|
I recently got the opportunity to refactor horrible Javascript I wrote right after I was hired. The code was for a website whose layout was to change dynamically between 4 different standard layout templates (home, an information page, an image gallery, and a horizontal accordion-style image gallery with categories). We used Prototype and scriptaculous for animating the layout transitions. I'd also like to mention that I had only a general knowledge of Javascript but wrote maybe 300 lines of JS prior to being hired, and this was my first project. The transition function body was something like this: code:
code:
In the refactor, I wrote a nice, clean gallery class that handles everything and even though it added about 400 lines to the project, it replaced 1400 lines of horrifying code just to support the different galleries. It never felt so good to hit delete on huge swaths of lovely, confusing code that I wrote myself years prior. Big Nubbins fucked around with this message at 16:11 on May 25, 2010 |
# ? May 25, 2010 16:07 |
|
Baby-sized horror that popped up today:code:
|
# ? May 27, 2010 01:18 |
|
Mustach posted:Baby-sized horror that popped up today: I don't get it.
|
# ? May 27, 2010 13:24 |
|
Should be char name[MAX_SIZE] = "Default";, I guess.
|
# ? May 27, 2010 13:31 |
|
Flobbster posted:That one's easy because there's only one correct answer: use the same conventions as the language and standard library that you're using. Some examples: PHP:
|
# ? May 27, 2010 16:43 |
|
code:
The real horror is that I didn't notice it until today after a few weeks of working on this horrible program.
|
# ? May 28, 2010 10:55 |
|
code:
|
# ? May 28, 2010 15:26 |
|
manero posted:
Jesus
|
# ? May 28, 2010 15:49 |
|
Vanadium posted:Should be char name[MAX_SIZE] = "Default";, I guess. Is that guaranteed to zero out the rest of the string? If I was paranoid enough about the rest of the string, I might go and zero it out by hand first like that too. FWIW, I just tested it with gcc and it did zero out the string, so it's probably alright.
|
# ? May 30, 2010 16:40 |
|
Yeah, it is, if you initialise an array but do not give values for all the elements, the remaining ones get set to zero.
|
# ? May 30, 2010 18:02 |
|
Is it OK to post it as a pre-emptive coding horror what Sun/Oracle's Lambda implementation for JDK7 will look like? Because seriously, look at this (from here):code:
|
# ? May 30, 2010 18:38 |
|
Well, with any luck lambdas won't make it into the Java7 release and we can breathe easy for a few more years. VVV oh, jesus gently caress. Internet Janitor fucked around with this message at 19:31 on May 30, 2010 |
# ? May 30, 2010 19:01 |
|
Internet Janitor posted:Well, with any luck lambdas won't make it into the Java7 release and we can breathe easy for a few more years. Sorry, the link I provided above is a repo push report from the official JDK7 Mercurial repository. They're in. In that form.
|
# ? May 30, 2010 19:23 |
|
Parantumaton posted:Is it OK to post it as a pre-emptive coding horror what Sun/Oracle's Lambda implementation for JDK7 will look like? Because seriously, look at this (from here): Err, that's not so bad, I don't think? The actual lambda part is just #(Integer x)(x + N), so the syntax is basically #(parameter list)(body). The rest of that junk looks like they're just explicitly qualifying their class when they call the exec helper function that they've written in their tests. The only that I'm not clear about is why the interface TU<T, U> that they've declared is necessary, or why they're invoking the lambda using a method on that interface instead of just doing something with the lambda itself. Hopefully things will become clearer further into development, but given the history of Java taking good ideas for features and loving them up completely, who knows!
|
# ? May 30, 2010 19:42 |
|
I'd argue that lambda expressions are not a good idea for Java. They don't improve the expressive power of the language- any sane implementation is just going to be sugar for anonymous classes and save us a few dozen characters, at the cost of adding new, irregular syntax. Historically, Java maintainers have been very conservative about tossing in new features, but Java7 is shaping up to look like C# envy.
|
# ? May 30, 2010 19:47 |
|
Internet Janitor posted:I'd argue that lambda expressions are not a good idea for Java. They don't improve the expressive power of the language- any sane implementation is just going to be sugar for anonymous classes and save us a few dozen characters, at the cost of adding new, irregular syntax.
|
# ? May 30, 2010 20:01 |
|
Internet Janitor posted:I'd argue that lambda expressions are not a good idea for Java. They don't improve the expressive power of the language- any sane implementation is just going to be sugar for anonymous classes and save us a few dozen characters, at the cost of adding new, irregular syntax. I've wasted enough time writing anonymous class instantiations of one-method interfaces for things like event listeners to say that you're absolutely wrong for thinking this way It's even worse if you're writing a class that exposes some kind of in listener functionality and you have to define a pointless interface on top of it. There are a lot of places where I would like to write code more naturally using higher-order functions and that's impossible without declaring/instantiating a bunch of pointless interfaces. Wouldn't it be nice if they added nice collection manipulation functions that took lambdas as arguments, something that would be unwieldy with anonymous types? You really think there's nothing gained by changing something like this: code:
code:
|
# ? May 30, 2010 20:01 |
|
The last time I did any serious amount of Java coding our school was locked on 1.4.2 and the syntax seems like it's way worse now. Of course, the JVM also had bugs if you had your CWD on your PATH variable so I guess I should count my blessings.
|
# ? May 30, 2010 20:24 |
|
Shumagorath posted:The last time I did any serious amount of Java coding our school was locked on 1.4.2 and the syntax seems like it's way worse now. Of course, the JVM also had bugs if you had your CWD on your PATH variable so I guess I should count my blessings. 1.5 is imo the minimum "good" Java. It introduced automatic [un]boxing, generics (you can laugh, but the language is much worse without them), and the enhanced for loop, all of which I feel are essential Java features. I hate when I have to work in 1.4 or below environments because I rely on these features so much. But I don't have to use Java for my job anymore, so I haven't touched it in ages I like to keep track of where it goes. Even if it's not always great to use, I think it's fun to watch the project evolve.
|
# ? May 30, 2010 20:46 |
|
Internet Janitor posted:I'd argue that lambda expressions are not a good idea for Java. They don't improve the expressive power of the language Neither does any feature once you have Turing completeness.
|
# ? May 30, 2010 21:05 |
|
Avenging Dentist posted:Neither does any feature once you have Turing completeness. This isn't strictly true, as there are programming language features which are not related to the primitive computational model, and thus aren't always reachable through pure Turing programming. For example, the SK combinator language is Turing-complete, but has no ability to perform IO with the outside world, so adding additional combinators which allow IO is a genuine increase in expressivity. That said, lambdas are not such a feature for Java.
|
# ? May 30, 2010 21:28 |
|
What exactly do we mean by "expressivity" here?
|
# ? May 30, 2010 21:32 |
|
Found this bit of java code to left pad a number with zeros...code:
|
# ? May 31, 2010 03:59 |
|
npe posted:Found this bit of java code to left pad a number with zeros... That's not a horror.
|
# ? May 31, 2010 06:06 |
|
shrughes posted:That's not a horror. code:
|
# ? May 31, 2010 06:29 |
|
shrughes posted:That's not a horror. pad(10, -1) pad(20, 0)
|
# ? May 31, 2010 06:33 |
|
yaoi prophet posted:Not to mention, what the gently caress is up with #? At least one other language, Clojure, uses # as a reader macro for declaring anonymous functions, the following two expressions are equivalent: code:
|
# ? May 31, 2010 16:18 |
|
manero posted:
Bonus points for using eval.
|
# ? May 31, 2010 17:25 |
|
|
# ? May 14, 2024 13:21 |
|
defmacro posted:At least one other language, Clojure, uses # as a reader macro for declaring anonymous functions, the following two expressions are equivalent: # is also used in javadoc tags such as {@link ClassName#methodName()}
|
# ? May 31, 2010 18:08 |