When the reviewer doesn't understand my Javascript it's his fault
-
@Gribnit said in When the reviewer doesn't understand my Javascript it's his fault:
@M_Adams - for JS in a browser.
Object.prototype is the true global...
I find it amusing to apply pedantry to JS, which is basically a pedant's nightmare.
-
@Gąska said in When the reviewer doesn't understand my Javascript it's his fault:
@gleemonk said in When the reviewer doesn't understand my Javascript it's his fault:
const PI = 3.1415
No.
const PI = 4*(1-1/3+1/5-1/7+1/9-1/11…)
-
@PJH good luck getting accurate results with floating-point arithmetic.
-
@PJH
Math.acos(0) + Math.asin(1)
-
@Gąska said in When the reviewer doesn't understand my Javascript it's his fault:
@PJH good luck getting accurate results with floating-point arithmetic.
Picky.
-
@kazitor said in When the reviewer doesn't understand my Javascript it's his fault:
@PJH
Math.acos(0) + Math.asin(1)
I've seen real life code that used arcsin to calculate π.
-
@Gąska said in When the reviewer doesn't understand my Javascript it's his fault:
@PJH good luck getting accurate results with floating-point arithmetic.
Convergence isn't exactly fast, either.
-
@topspin at compile time, all calculations are instant.
-
sqrt(6*(1+1/4+1/9+1/16+...))
-
@Gąska said in When the reviewer doesn't understand my Javascript it's his fault:
@topspin at compile time, all calculations are instant.
Allowed source line length is, however, limited.
-
@topspin thankfully, so is float precision.
-
@Gąska said in When the reviewer doesn't understand my Javascript it's his fault:
so is float precision
Arbitrary precision libraries exist. They're slow, but useful for validating the outputs of your faster production algorithms.
-
@topspin said in When the reviewer doesn't understand my Javascript it's his fault:
@Gąska said in When the reviewer doesn't understand my Javascript it's his fault:
@topspin at compile time, all calculations are instant.
Allowed source line length is, however, limited.
This is the sort of thing metatemplate programming was invented for. I sure this could be mangled to do this small task.
-
@dkf said in When the reviewer doesn't understand my Javascript it's his fault:
@Gąska said in When the reviewer doesn't understand my Javascript it's his fault:
so is float precision
Arbitrary precision libraries exist.
Arbitrary precision libraries don't make full expansion of irrational numbers either.
-
@Gąska said in When the reviewer doesn't understand my Javascript it's his fault:
Arbitrary precision libraries don't make full expansion of irrational numbers either.
But they can give you as many digits as you want, and those digits will be correct (to within some definition of “correct” which is a bit complicated and depends on the underlying math). The awkward part is that it might take a lot of computation to decide a particular digit in a pathological case.
-
@gleemonk Ah I see, he doesn't get the difference between a "compile-time constant" and a "variable whose contents don't change after it's initialized".
Javascript being "higher-level" than C++, I'd have expected it to haveconst
restricted to the former, like in C# (orconstexpr
in modern C++).
-
@gleemonk said in When the reviewer doesn't understand my Javascript it's his fault:
: Look here I define the callback to this request as a closure. Easy!
: Extract it and put it somewhere else!
: But then I don't have access to the local constants!That's the point of using closures!
-
@Gąska said in When the reviewer doesn't understand my Javascript it's his fault:
@topspin thankfully, so is float precision.
A simple test shows that convergence is logarithmic.
Using single precision floats the numerical error for pi is on the order of 10-8, so you need about 108 summands in your source file, i.e. about 109 characters (1GB). To reach double precision accuracy you're in the order of 1016 or something like that.
-
@RobFreundlich said in When the reviewer doesn't understand my Javascript it's his fault:
Have I ever worked in an environment that had such tooling? No.
Can I envision such an environment? Yes.
Does my current company have the time and resources to set up such an environment? No. sigh.
Does any company have the time and resources to set up such an environment? Probably not. sigh.You should be able to fairly easily set that up with any of the JetBrains IDEs, but I think you'd have to switch the code style when you want to start editing code, and switch it back and reformat changed files before committing.
Seems like a plugin could handle it, if one existed.
-
@PJH said in When the reviewer doesn't understand my Javascript it's his fault:
@topspin said in When the reviewer doesn't understand my Javascript it's his fault:
@Gąska said in When the reviewer doesn't understand my Javascript it's his fault:
@topspin at compile time, all calculations are instant.
Allowed source line length is, however, limited.
This is the sort of thing metatemplate programming was invented for. I sure this could be mangled to do this small task.
Maximum template instantiation depth (if you're using the same formula) will be reached even sooner, though.
-
@Medinoc said in When the reviewer doesn't understand my Javascript it's his fault:
About the ALL_CAPS thing, did code in other languages before? Because for me, who's coded in C and C++ before, that is how you're supposed to declare constants in those languages.
In fact, I didn't even know javascript even had globals. Or
const
.JS const ≈ final in C-style languages. I wouldn't call every final local variable I had a constant (even though it really is).
-
@JazzyJosh said in When the reviewer doesn't understand my Javascript it's his fault:
@RobFreundlich said in When the reviewer doesn't understand my Javascript it's his fault:
Have I ever worked in an environment that had such tooling? No.
Can I envision such an environment? Yes.
Does my current company have the time and resources to set up such an environment? No. sigh.
Does any company have the time and resources to set up such an environment? Probably not. sigh.You should be able to fairly easily set that up with any of the JetBrains IDEs, but I think you'd have to switch the code style when you want to start editing code, and switch it back and reformat changed files before committing.
Seems like a plugin could handle it, if one existed.
We use JetBrains IDEs, and I'd love a plugin like that. If someone wants to write one, I'll gladly beta test it for them.
-
@gleemonk I was responding more to people suggesting tools to force everybody else to do things their way.
In your specific case, I don't agree with the complaint about capitalized constants. I started my career in languages where this was common practice. There's nothing inherently wrong with it. In fact, practices like that and overt type declarations (F late-binding tricks like var) make it so I can write code in Notepad if I have to instead of depending on the latest color-coded IDE. The real problem, as I see it, is that this co-worker is writing very long methods or spaghetti code. That's what should be addressed, not capitalized constants.
I've done code review. My rules (such that they are) are much looser for local symbols. It doesn't matter what they're called because nothing else has to reference them. It doesn't matter how they're arranged because the compiler throws out the spaces and line breaks. What's important is how the code works. Is it relatively efficient and does it cover corner cases? The visible API is a second consideration. More people are going to work with and depend on that than will ever even see the inside of your function. Unless A) your code works badly or B) you don't document anything, in which case, yeah, everybody that uses your functions has to jump into the source to find out WTF is going on. Both of those are orders of magnitude worse sins than formatting.
On the other side of this...I've been through some rough code reviews. I've had style Nazis tell me they weren't going to follow their own rules because they didn't want to. I've had style Nazis present conflicting rules and refuse to tell me which rule to follow because they liked harassing me in circles. I've had style Nazis threaten to fire me over too many or too few imported namespaces. I've had style Nazis kick back unsigned integers because they're "not standard" and the correct spelling of US states because it was "too risky." All while letting a virtual torrent of WTFs straight from this site sail on through.
I worked one place where I was handed a date lookback function that, instead of using the built in date functions, did raw subtraction, string concatenation, and manual reparsing. A quarter of the time, it produced negative months or dates like February 31st. It was reviewed and passed by two people before it was supposed to go into my common library. Those same idiots threw a hissy fit over me using "System.Int32" instead of "int" because a CLR type kicked their puppy or something.
At another, the reviewer had a lousy undocumented "framework" where they would not acknowledge bugs and locked the repository. So I'd frequently have to choose between having a workaround kicked back for "not following standards" or a "standard" approach kicked back for not working. Another fun issue was how they loved to rethrow exceptions the way that dumps the stack trace so that the error came out as "oops, something happened, try again" with no point of origin. Yet, here I was, explaining (in vain) why I used structs sometimes or put parentheses around my casts, when I wasn't sitting on my hands for lack of real work to do.
At still another, fat lot of good their sad devotion to camel casing and function arguments on separate lines did to stop anybody from popping up MsgBox() calls on a headless server (or letting unchecked type conversions and PHP-like "falsey" logic do it).
In every case, if I'd known sort of what inept, incurious, micromanaging assholes they were beforehand, I would've kept looking.
@dcon Faulty premise. No place has 23423490 styles. If you do, your real problem is either out-of-control turnover or lack of ownership. Also, if I'm more consistent than the rest of the team put together, why should I have to constantly change to hit a moving target? Why don't you take a merit-based approach? Use metrics to find out who has the lowest bug count or least amount of rework or whatever. It's hard to do if you treat your developers less like craftsmen with ownership and more like a swarm of interchangeable bees but that's because of poor management. It's the same sort of mindset that makes you babysit 100 H1Bs because 1 rock star told somebody no once.
-
@topspin said in When the reviewer doesn't understand my Javascript it's his fault:
sing single precision floats the numerical error for pi is on the order of 10-8, so you need about 108 summands in your source file, i.e. about 109 characters (1GB).
A quick test converges to float precision after 294338 terms, which is a bit less than 108. But, yeah, it's certainly not the most efficient way to get π. 266306 terms to get within 1 ulp.
Edit: Note, if you do it properly, it increases to 4839519 terms, so roughly 108, though.
Edit:
Maximum template instantiation depth (if you're using the same formula) will be reached even sooner, though.
Game Programming Gems 1 had "Fast Math Using Template Metaprogramming" (~2000). Not sure if they computed π explicitly, but they did do compile-time sin/cos methods.
Filed under: 22/7
-
val pi = 3;
-
@Gribnit this is fine. Even though a bit useless.
-
@Gąska TIL that "3" is a better π approximation than "3.1415"
You know, because one's 95% accurate and the other's only 99.997%.
-
@kazitor It is a mystery.
That, or my flamebait was so far off as to be "safely and obviously wrong" or "this is good enough for the weird hack we are doing" vs "this might get used as pi where it mattered"
-
@topspin said in When the reviewer doesn't understand my Javascript it's his fault:
@PJH said in When the reviewer doesn't understand my Javascript it's his fault:
@topspin said in When the reviewer doesn't understand my Javascript it's his fault:
@Gąska said in When the reviewer doesn't understand my Javascript it's his fault:
@topspin at compile time, all calculations are instant.
Allowed source line length is, however, limited.
This is the sort of thing metatemplate programming was invented for. I sure this could be mangled to do this small task.
Maximum template instantiation depth (if you're using the same formula) will be reached even sooner, though.
Stop taking me seriously!
-
@kazitor said in When the reviewer doesn't understand my Javascript it's his fault:
@Gąska TIL that "3" is a better π approximation than "3.1415"
You know, because one's 95% accurate and the other's only 99.997%.
One of them might not have the same precision (integers tend to do that), but at least it's not blatantly wrong with its last digit.
-
@PJH said in When the reviewer doesn't understand my Javascript it's his fault:
@topspin said in When the reviewer doesn't understand my Javascript it's his fault:
@PJH said in When the reviewer doesn't understand my Javascript it's his fault:
@topspin said in When the reviewer doesn't understand my Javascript it's his fault:
@Gąska said in When the reviewer doesn't understand my Javascript it's his fault:
@topspin at compile time, all calculations are instant.
Allowed source line length is, however, limited.
This is the sort of thing metatemplate programming was invented for. I sure this could be mangled to do this small task.
Maximum template instantiation depth (if you're using the same formula) will be reached even sooner, though.
Stop taking me seriously!
Blame @Gąska.
-
@topspin for what? For people missing my obvious joke and pedantry about 5/4 rounding?
-
@Zenith said in When the reviewer doesn't understand my Javascript it's his fault:
What's important is how the code works. Is it relatively efficient and does it cover corner cases? The visible API is a second consideration.
Whether the code works at all is primary. Then whether it covers corner cases and can be used by others (e.g., does it have docs). Then efficiency and
readabilitymaintainability (with the order depending on what the code in question is used for). I usually prefer to tackle maintainability before efficiency, as improving efficiency is a maintenance action, but sometimes efficiency comes earlier because there's a need to reach specified performance levels as part of acceptance testing.Sounds like you've worked with some jerks who didn't understand the importance of getting things actually correct in the first place.
-
@Gąska said in When the reviewer doesn't understand my Javascript it's his fault:
For people missing my obvious joke and pedantry about 5/4 rounding?
Use
22.0 / 7
. It's not right, but it's the best approximation with smallintegerswhole numbers.
-
@dkf I can't even figure out what problem you're trying to solve with that or where you've read about it.
-
@dkf I will never quit evangelising 355/113. Memorable and correct to six decimal places.
-
@kazitor so are the six decimal places.
-
@Gąska well, yes, that's my preferred method :)
I more mean that approximation in favour of 3 and one seventh.
-
@Gąska said in When the reviewer doesn't understand my Javascript it's his fault:
@topspin for what?
Does it matter, really?
-
@topspin now I know how Donald Trump feels.
-
@Gąska said in When the reviewer doesn't understand my Javascript it's his fault:
now I know how Donald Trump feels.
Everbody keeps wondering if your hair is real?
-
@Luhmann Status: trying to think up a line that would connect Trump's hair with Fanta sea.
Alternative joke:
Is this the real hair
Is this just composite
-
@Gąska said in When the reviewer doesn't understand my Javascript it's his fault:
I can't even figure out what problem you're trying to solve
Quick estimate on paper. Lack of FPU or related reason for doing integer-only arithmetic.
Filed under: Writing C/C++ that doesn't have a standardized predefined pi constant? #sadface
-
@Zenith said in When the reviewer doesn't understand my Javascript it's his fault:
@gleemonk I was responding more to people suggesting tools to force everybody
elseto do thingstheirin a standard way way.FTFY
My style looks very different from AirBnB style. But people don't accept my style. So I accept AirBnB over any other style. Keeps the diffs readable.
In your specific case, I don't agree with the complaint about capitalized constants.
I'm not complaining about constants, I'm complaining about variables. Don't you go on me.
I started my career in languages where this was common practice. There's nothing inherently wrong with it.
Show me one project where local variables are ALL_CAPS because they are
const
orfinal
and I might reconsider.In fact, practices like that and overt type declarations (F late-binding tricks like var) make it so I can write code in Notepad if I have to instead of depending on the latest color-coded IDE.
Well there's your problem.
The real problem, as I see it, is that this co-worker is writing very long methods or spaghetti code. That's what should be addressed, not capitalized constants.
I did address it. What are you on about?
I've done code review. My rules (such that they are) are much looser for local symbols. It doesn't matter what they're called because nothing else has to reference them. It doesn't matter how they're arranged because the compiler throws out the spaces and line breaks.
What's important is how the code works. Is it relatively efficient and does it cover corner cases? The visible API is a second consideration. More people are going to work with and depend on that than will ever even see the inside of your function. Unless A) your code works badly or B) you don't document anything, in which case, yeah, everybody that uses your functions has to jump into the source to find out WTF is going on. Both of those are orders of magnitude worse sins than formatting.
Formatting is where it begins. If you can't follow some readable standard, I'm not going to look at your code. Or you pay me to fix it. Because it's automatically, indisputably, and rightfully presumed to be shit.
After that, if your naming scheme is inconsistent or hinders readability, I'll assume that the structure is shit because you can't even get that basic thing sorted.
Then, if your local structure is shit, I assume you're either inexperienced or didn't have time to fix it up.
After all that, I'll consider the public API. But you might not have much control over that. So I'm not going to judge harshly.
On the other side of this...I've been through some rough code reviews. I've had style Nazis tell me they weren't going to follow their own rules because they didn't want to. I've had style Nazis present conflicting rules and refuse to tell me which rule to follow because they liked harassing me in circles. I've had style Nazis threaten to fire me over too many or too few imported namespaces. I've had style Nazis kick back unsigned integers because they're "not standard" and the correct spelling of US states because it was "too risky." All while letting a virtual torrent of WTFs straight from this site sail on through.
So you've worked with ?
I worked one place where I was handed a date lookback function that, instead of using the built in date functions, did raw subtraction, string concatenation, and manual reparsing. A quarter of the time, it produced negative months or dates like February 31st. It was reviewed and passed by two people before it was supposed to go into my common library. Those same idiots threw a hissy fit over me using "System.Int32" instead of "int" because a CLR type kicked their puppy or something.
My sympathy.
At another, the reviewer had a lousy undocumented "framework" where they would not acknowledge bugs and locked the repository. So I'd frequently have to choose between having a workaround kicked back for "not following standards" or a "standard" approach kicked back for not working. Another fun issue was how they loved to rethrow exceptions the way that dumps the stack trace so that the error came out as "oops, something happened, try again" with no point of origin. Yet, here I was, explaining (in vain) why I used structs sometimes or put parentheses around my casts, when I wasn't sitting on my hands for lack of real work to do.
My condolences.
At still another, fat lot of good their sad devotion to camel casing and function arguments on separate lines did to stop anybody from popping up MsgBox() calls on a headless server (or letting unchecked type conversions and PHP-like "falsey" logic do it).
In every case, if I'd known sort of what inept, incurious, micromanaging assholes they were beforehand, I would've kept looking.
Maybe consider that you have your own collaboration "issues" that prevent you from working with pragmatic people
-
@Gąska said in When the reviewer doesn't understand my Javascript it's his fault:
@dkf I can't even figure out what problem you're trying to solve with that or where you've read about it.
22 / 7 is the approximation that was used since forever. It's amazingly accurate given its simplicity, so it was historically very important.
-
@boomzilla it's amazing how irrelevant your answer is while still looking like it's on topic.
-
@Gąska said in When the reviewer doesn't understand my Javascript it's his fault:
@boomzilla it's amazing how irrelevant your answer is while still looking like it's on topic.
"When the replying poster doesn't understand my post and it's his fault."
-
@boomzilla maybe don't reply to posts you don't understand?
-
@kazitor said in When the reviewer doesn't understand my Javascript it's his fault:
@dkf I will never quit evangelising 355/113. Memorable and correct to six decimal places.
TIL. Thanks!
-
@Gąska said in When the reviewer doesn't understand my Javascript it's his fault:
@boomzilla maybe don't reply to posts you don't understand?
What do you mean by understand?