Jabor posted:It's the whole lambda scoping thing. Lambdas close over variables, not values. Evil, but I see how it kinda makes sense. For whatever reason it didn't catch my eye at first, why use return BuildAction(wrapperAction, ++i); instead of return BuildAction(wrapperAction, i+1); ? I mean, you'd expect i to go out of scope after that so why even bother changing its value. Except it does stay in a scope That should have raised a flag.
|
|
# ? Jul 8, 2011 04:29 |
|
|
# ? Apr 18, 2024 04:48 |
|
nielsm posted:Evil, but I see how it kinda makes sense. It allows you to have persistent, modifiable state in a lambda, which you you either can't or it's-a-real-pain-to-do otherwise. The obvious "toy example" is a lambda which tracks how many times it's been called, but there are some actual useful uses for it. For example, we could implement a PRNG as so (largely psuedocode): code:
|
# ? Jul 8, 2011 05:29 |
|
code:
|
# ? Jul 11, 2011 23:14 |
|
Fehler posted:
|
# ? Jul 12, 2011 03:11 |
|
Fehler posted:
Defining '2' as a constant has a legitimate use for static analysis tools, further mo- haha I'm just playing. Why would anyone do that? Is there a language where you have to do stuff like this? My work wants me to write my own USB stack so that I can learn usb inside and out, so far its 2kB of coding horror, could post the whole thing
|
# ? Jul 12, 2011 03:17 |
|
Well poo poo, and here I thought reinventing the wheel was over after your undergrad. At least I hope you don't have to do it on 30 year old development boards.
|
# ? Jul 12, 2011 03:26 |
|
Ensign Expendable posted:Well poo poo, and here I thought reinventing the wheel was over after your undergrad.
|
# ? Jul 12, 2011 04:52 |
|
BigRedDot posted:Are you kidding? Some folks specifically want 13 sided wheels, instead of the 16 sided ones the last guy made, and who the hell are you? Seriously, I hugely prefer making my own wheel for a few months before I have to work on the lumpy rear end-backwards wheel that exists.
|
# ? Jul 12, 2011 05:11 |
|
dietary supplement posted:Seriously, I hugely prefer making my own wheel for a few months before I have to work on the lumpy rear end-backwards wheel that exists.
|
# ? Jul 12, 2011 05:12 |
|
BigRedDot posted:Now I really wish I had the photoshop skills to make an image of a wheel with a bunch of backwards asses protruding from it. You are posting on an internet forum about computer codes, don't pretend you don't have the free time to learn photoshop. I guess I'll edit in some content, ran across this code snippet today. Likely an ASM oldie being forced into C. code:
Jerry Bindle fucked around with this message at 05:26 on Jul 12, 2011 |
# ? Jul 12, 2011 05:16 |
|
i needed to iterate over an at-most 3x3 rectangle in a 2d array so naturally I wrote this code:
|
# ? Jul 12, 2011 06:56 |
|
Aleksei Vasiliev posted:i needed to iterate over an at-most 3x3 rectangle in a 2d array Doesn't have nested ternary operations, not horrific enough. Seriously, though, .
|
# ? Jul 12, 2011 07:16 |
|
Aleksei Vasiliev posted:Labeled breaks aren't the same thing as gotos. Completely abuse the gently caress out of exceptions?
|
# ? Jul 12, 2011 07:50 |
|
Scaevolus posted:Looks like a FORTRAN programmer has been forced to write C, and is resisting. I've seen C written like that by an engineer who had only ever done verilog. Every single loving constant was defined as such Including things like const_two = 2 , etc. Oh and the macros. God drat it macros are cool, but when every loving operation is first defined as a macro THEN applied to code, it very rapidly becomes brain damage inducing trying to read.
|
# ? Jul 12, 2011 07:51 |
|
duck monster posted:I've seen C written like that by an engineer who had only ever done verilog. Every single loving constant was defined as such Including things like const_two = 2 , etc. Ever heard of obsfuscation? Its a common thing to obsufscate code to make you "irreplacable" and so secure your position in a job. (yeah right that will work right)
|
# ? Jul 12, 2011 09:26 |
|
Fehler posted:
Maybe they use a static analysis tool or high warning level and don't want to be bombarded with loss of precision messages if they decide to change real to float?
|
# ? Jul 12, 2011 12:38 |
|
No need to add comments on any of this poo poo, it's self-documenting.code:
|
# ? Jul 12, 2011 14:12 |
|
Is e some kind of insane list of lists (of lists)?
|
# ? Jul 12, 2011 16:58 |
Ensign Expendable posted:Is e some kind of insane list of lists (of lists)? Looks like some DOM-alike tree structure. I assume getFirst() actually means "get first child", and not "get first on this level", otherwise it wouldn't really make sense. The code would make more sense if you had an example of the document tree it's presumably working on.
|
|
# ? Jul 12, 2011 17:01 |
|
Fehler posted:
|
# ? Jul 12, 2011 17:20 |
|
nielsm posted:The code would make more sense if you had an example of the document tree it's presumably working on. Yes it would, wouldn't it. It would also make more sense if the coder would have explained what he was trying to do. And instead of using e.getParent().getNext().getNext().getFirst().value, he would or could use something like $('foo12').value. Those get-methods are part of MooTools. There is all kinds on insane poo poo in this codebase, but I'm unfortunately starting to understand how it works. poo poo like <div class = "ColorDropDown CoolBeans WhatIsThisShit">, which gets processed by "the framework", which then splits that class with space, then does stuff like: code:
Wheany fucked around with this message at 18:30 on Jul 12, 2011 |
# ? Jul 12, 2011 18:28 |
|
Wheany posted:No need to add comments on any of this poo poo, it's self-documenting.
|
# ? Jul 12, 2011 20:19 |
|
No specific examples but I have a million line code base (ANSI-C) that assumes that divide by 0 should return 0.
|
# ? Jul 12, 2011 20:56 |
|
Well what else would you return!
|
# ? Jul 12, 2011 21:28 |
|
ohgodwhat posted:Well what else would you return! Nothing; however, demons may fly out your nose as a side effect
|
# ? Jul 12, 2011 21:29 |
|
The1ManMoshPit posted:Maybe they use a static analysis tool or high warning level and don't want to be bombarded with loss of precision messages if they decide to change real to float? Misogynist posted:I'm curious what they're doing that demands pi to that precision but still uses IEEE floats
|
# ? Jul 12, 2011 23:43 |
|
PrBacterio posted:That *kind of* looks like he's doing a tree node rotation there, but probably not. At least whenever I've implemented AVL trees or somesuch the resulting code often didn't look all that dissimilar to that ... :o No, he is assigning a value from a dropdown (a <select> tag) to a checkbox (<input type=checkbox>). Why? I have no idea. Why don't the <select> and <input> tags have ids, so he could have done $('input_id').value = $('select_id').value? I have no idea. The only way to know what that code was doing was to put a breakpoint in that function and watch e's value. It also would have helped if there was any other comments in this code except: code:
code:
code:
|
# ? Jul 13, 2011 08:43 |
|
var is_feature_supported = ["true", "true", "false", "true", "false"]; At first glance, that might not look odd, and I sure missed it at first. But those are not booleans values, those are strings. So if( is_feature_supported[i] ) always gets executed, because in JavaScript non-empty strings are always true.
|
# ? Jul 13, 2011 14:53 |
|
And that's why you always, always, always use equals equals equals in javascript!
|
# ? Jul 13, 2011 16:03 |
|
NotShadowStar posted:And that's why you always, always, always use equals equals equals in javascript! Then you're be writing is_feature_supported[i] === "true" which would be a worse horror. If you're going to play along with that array of features business then just use actual bools.
|
# ? Jul 13, 2011 16:32 |
|
A static code analysis like JSLint will pick up on that if you don't. If you force yourself to do if(something === "true") then most people would go 'huh, what the hell am I doing?' It's not THAT bad of a horror though, turning it into an object would be much clearer. if (featuresSupported.integratedButtSex) {}
|
# ? Jul 13, 2011 16:43 |
|
featuresSupported.integratedButtSex = "false";
|
# ? Jul 13, 2011 16:50 |
|
When I wrote this a few weeks ago I thought it was brilliantcode:
This morning I ran across it and had to wonder what the hell it did. Some day I'll get around to reading code complete that I've had on my shelf for months.
|
# ? Jul 13, 2011 16:51 |
|
"<< 1" instead of "* 2" is generally a horror.
|
# ? Jul 13, 2011 17:15 |
|
I dunno, I'd be okay with it if that was a | and not a +.
|
# ? Jul 13, 2011 17:18 |
|
Scaevolus posted:"<< 1" instead of "* 2" is generally a horror. Look at that code he wrote again. Look at those names. That stuff probably gets dumped into some crappy compiler for whatever embedded system it runs on that has no concept of strength reduction or peephole optimizations. You're still better off wrapping the thing in a macro (I assume the compiler doesn't support inline functions either ), but that's really no worse than manually unrolling a loop when the compiler won't do it for you. So long as you document it.
|
# ? Jul 13, 2011 17:52 |
|
Scaevolus posted:"<< 1" instead of "* 2" is generally a horror. Well, assuming this is C/C++, plus is higher precedence than shift, so what that actually does is code:
|
# ? Jul 13, 2011 18:07 |
|
Presto posted:Well, assuming this is C/C++, plus is higher precedence than shift, so what that actually does is Wow good catch. At least I thought it worked right. Also it turns out that power of two multiply operations all compile to shift instructions, I was worried that they would link in the multiply library for parts without a hardware mul. Edit: I had tested it with 2* in there, but then switched it to <<1 because I'm so clever!! Jerry Bindle fucked around with this message at 18:19 on Jul 13, 2011 |
# ? Jul 13, 2011 18:13 |
|
|
# ? Jul 13, 2011 18:16 |
|
|
# ? Apr 18, 2024 04:48 |
|
dietary supplement posted:Edit: I had tested it with 2* in there, but then switched it to <<1 because I'm so clever!!
|
# ? Jul 13, 2011 18:25 |