Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

CeciPipePasPipe posted:

Not sure why they escape <img> and <iframe> tags, but it may be related to this: http://stackoverflow.com/questions/236073/why-split-the-script-tag-when-writing-it-with-document-write

No it's almost certainly to get past ad-blockers as others mentioned earlier. Splitting up an img or iframe tag may confuse an ad-blocker scanning HTML source for any img and iframe tags pointing at such-and-such ad domains. e.g. an ad-blocker looking for htmlsource.Contains("<img>") won't match "'<i' + 'mg>'". There's no technical reason to split up html tags in document.write except </script>.

Adbot
ADBOT LOVES YOU

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost
Lambdas are awesome, I can't imagine why anyone would think otherwise. The alternative is the old 2.0 anonymous delegate syntax which was ugly as hell and hard to read. Unless you've been in bracket land your entire programming career, lambdas read very naturally.

var I can understand because it can make code harder to read at a glance. Yeah weakly-typed languages aren't inherently harder to read than strongly-typed languages but when you run into what looks like weak typing in the middle of strongly-typed code it forces you to put on the breaks.

Having said that its usage in limited areas (like foreach loops on some complicated enumeration or linq expression results) it does make the code more compact without sacrificing too much clarity.

dynamic scares me. Everyone who *thinks* var introduces weak-typing is gonna fuckin' love dynamic.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

king_kilr posted:

Congrats, you don't know the difference between strong/weak typeing and static/dynamic. Have a cookie.

You're right I mixed the two up. I know the difference I just don't keep the terms straight in my head as I don't jump between those different worlds very often.

Regardless I don't think that has anything to do with my particular criticisms/support for lamdbas, var, and dynamic in C# :confused:

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

ShoulderDaemon posted:

The end result seems to be a feature that is only used in relatively few simple cases, as neither group really trusts it to do what they want.

The intention I got when C# 3.0 was just coming out is that var was originally intended for a pretty narrow case. It arose out of LINQ's need to generate anonymous types where the programmer simply can't specify the type since it's unknown. The fact that it's only valid in local scope and must be declared and initialized in the same statement seems to support the fact that they weren't going out of their way to introduce type inference all over the language.

But then I see tools like Resharper suggest you type all your local variables as var if you're initializing them and I can't discern if that's what MS intended or if the community just went crazy with the usage because it was new and shiny and they didn't have to type Dictionary<string, int> anymore or whatever.

Either way I think its overuse leads to less readable code. I tend to keep it within the scope of LINQ expressions and use explicit typing everywhere else.

Dr Monkeysee fucked around with this message at 20:36 on Jan 28, 2010

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

WildFoxMedia posted:

If this doesn't make you angry, lemme add to this. This is part of a checkout setup and cybersource is the name of the CC gateway. The idiot who wrote this code also thought it was a stellar idea to store the raw request and raw response to/from cybersource.

... And if you dont get the signifigance - He was storing the raw request, which included full CC number, expiration date, cardholder name and CVV - ALL UNENCRYPTED IN loving JSON SYNTAX IN A loving MYSQL DATABASE.

Haha that's horrible. We've recently started doing some work involving a payment gateway and the very first thing that legal, engineering, product management, and accounting all got on board for was NEVER LET CREDIT CARD INFO TOUCH OUR NETWORK. The lengths we have to go to avoid that arguably spawn their own coding horrors but the wrath that can be brought down upon your company for storing CC info insecurely can literally destroy your business. Aside from the legal liabilities it exposes you to, the community of payment gateways will simply stop doing business with you if you're found out of compliance.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

Milotic posted:

Huh? Web development with ASP.NET is fine. There's stuff that could be improved, definitely, and how Microsoft implemented AJAX for ASP.NET can be an abomination unto God sometimes, and the page event life cycle is a bit lovely in places, but really, I've seen worse technologies and frameworks.

We need a distinction between "web devs" and application devs that are writing for the web. It used to a be a "web developer" was someone who hacked DHTML and CSS to get cool rollovers but now so much real functionality is moving to web interfaces and you have these enterprise-level web development platforms that the distinction between "real dev" and "web dev" is basically non-existent (except for the abomination of writing a decent UI in HTML/CSS).

My workplace employs an engineering organization made of CS degrees all with backgrounds in C++/C#/Java/etc and we all develop complex web apps in either Java or ASP.NET. The work we do isn't qualitatively different from desktop apps. But we also have "web devs" in the marketing department who's job is to create light-weight HTML pages that might pull some data down via AJAX but by-and-large aren't backed by a server-side application codebase.

So, am I a web dev if I spend all day in ASP.NET? What's that make the HTML guy in the other department? Are the people creating Google Maps in the same class of people that customized their Livejournal template? Obviously not but the term "web dev" still seems to sit awkwardly between those extremes.

I see the distinction "web dev" and "web app dev" but that doesn't seem any less awkward.

Nomnom Cookie posted:

It's not so much that I have any issues with ASP.NET as it is that the entire class of problems ASP.NET is designed to solve is utterly uninteresting to me. Playing mix-and-match with tags and C# to shove data around in slightly different ways just isn't what I want to do with my life.

Although I do think ASP.NET is entirely the wrong direction for Web development to take and hope it's an evolutionary dead-end, it is at least a decent implementation. You're right; my prospects could be worse.

ASP.NET the platform is pretty solid in my opinion. WebForms is just the application framework built on top of it. And at this point we've essentially abandoned it for ASP.NET MVC which fits much much better in the web world. It's a testament to the flexibility of ASP.NET that you can essentially rip out WebForms and replace it with something else and it still works.

Dr Monkeysee fucked around with this message at 19:11 on Mar 5, 2010

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

rt4 posted:

Then they get shoehorned into writing stuff they don't understand to try to save money.
Then it goes way too far and they start making databases and PHP programs based on some tutorial they read.

:ughh:

Haha yeah we specifically had to set up PHP in the publishing environment so they could do some server-side stuff if it came up.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost
Having the hotel accept the scanner and process keyboard input seems like the text-book example of giving an object too many responsibilities. The concept of "registering a guest" is independent from "parsing user input" and in the real world I certainly wouldn't expect a hotel API to encompass input processing.

Sounds like she's emphasizing the encapsulation side of OOP too much because hey you've got to process the input somewhere and you've got this hotel object so why not hide everything behind a single call.

Ryouga Inverse posted:

yeah, this design makes the most sense to me, you don't want to be doing the input part in main either - she's right that the object should encapsulate all of the code that registers a guest, but wrong in how it should be divided among methods, basically

Given that this is a school assignment and not some reusable module, main is a perfectly reasonable place to process input. It makes more sense than shoving it into hotel.

Dr Monkeysee fucked around with this message at 20:53 on Apr 15, 2010

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

Ryouga Inverse posted:

If you think that "because it's a school assignment" is a good reason to stick a bunch of business logic in main, then I don't know what to tell you. Nothing important goes in main.

It really depends on the class' subject matter but expecting students to implement good software engineering practices at every level for every assignment when the whole point of the assignment is likely very narrowly defined is total overkill. Designing this Hotel class is probably the entire project. If someone did this in the real-world you'd be fully justified in telling them their code sucks and they should rework it.

Abstracting away any dependency layers is obviously a best practice but school projects just don't operate at that level.

Were you the guy in class that was pissed no one else did the extra credit assignments?

Dr Monkeysee fucked around with this message at 21:09 on Apr 16, 2010

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

Ryouga Inverse posted:

No, I don't care if people want to gently caress off in class, and I don't care how awful the code is.

Maybe I came across a bit harsh, but what I mean is that if you're going to discuss the design of an app, the fact that it's for a school assignment isn't important and doesn't justify a crappy design.

No one expects you to just pull SE best practices out of your rear end. Well, at least I don't. But if I were posting in the coding horrors thread critiquing someone else's code, when my own code isn't really that great either (though certainly better), I'd appreciate critique on it too.

The whole point is to learn and become a better developer, right?

I guess my position is whether the code is crappy or not is dependent on context and in the context of a school assignment doing input processing in main is pretty frickin' low on the list of coding sins.

But whatever. The real answer is do whatever won't piss off the professor :) If she really gives a big poo poo about having the hotel process the input then do that. There's plenty of time to learn best practices.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

Avenging Dentist posted:

Unit testing does not require (or even want) full code coverage so having logic in main really doesn't do anything to detract from that.

Yeah you're not going to be able to unit test the actual input processing anyway so as long as it's not wrapped up with the stuff you do want to unit test it really doesn't matter.

This is largely moot anyway. He's not writing unit tests for a drat school assignment.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

Plorkyeran posted:

Why? I wrote unit tests for nearly every school assignment I did.

Things have changed since I was in school. To be fair unit tests were some weird obscure thing the Smalltalk community was pushing at the time.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

Daald posted:

I think the funniest thing was him naming that variable "wastedSpace". I can already see his reasoning.

1. Hey I need to parse this string to integer.
2. Wouldn't it be nice if I found a function that tells me if it is a valid string?
3. Let me see if I find it...ohh there is one...tryparse...looks like it.
4. WTF? It needs me to pass it an integer...WTF for? Ahh well stupid MS api. Here is your stupid variable.
5. Cool, I can parse it. Now let me call the parse function.

To compound it even further the signature of the method is TryParse(string s, out int result).

Hmm... what could result possibly mean... oh well whatever time to call Parse and store the value in my local variable named result.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

oneinchhard posted:

code:

public class SomeClass
{
    public string SomeString1 { get; set; }
    ...
}

...elsewhere in the code:

string someVar = someClassInstance.SomeString1.ToString();


For some reason I see this in contractor code ALL THE TIME. Apparently contractors are really really enthusiastic about toString'ing strings.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

Mustach posted:

Maybe it's out of habit from calling ToString() on everything else. Who needs any other data type? Strings are simple and easy to understand!

We need a language where the only data type is a string and when you do non-string operations like arithmetic it converts it to some internal representation, does the bit shuffling, and returns the result as a string. All functions are simply extending the string type.

But you still have to explicitly declare your variables as strings JUST TO MAKE SURE.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost
This is why regexes themselves are the coding horror.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

TRex EaterofCars posted:

No way. Regular expressions are good tools. The coding horror is people using them to solve every problem relating to string processing they encounter.

I'm being facetious. Regexes are obviously extremely useful but it's remarkable how much trouble people have with them unless you're working with them literally every day. If you were trying to invent a syntax that was scientifically designed to be impossible to remember or keep in your head at once you couldn't do much worse than the standard regex syntax. It's like something invented by an evil robot.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost
In web development there aren't really any coding horrors that can outdo IE itself.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost
Despite the sheer amount of pain and suffering IE has caused in my professional life I have to feel bad for the team itself. It can't be easy trying to turn the IE ship around and bring it up to par with modern browsers while still maintaining support for all the integrated shell stuff Trident is called on to do.

The problem is Firefox, Opera, Chrome, Safari, etc. are *just* browsers. IE is built on a rendering engine that does a lot more than just web browsing, and a lot of those decisions about what else it needs to do were made 10 years ago.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost
I regularly find naming to be the hardest part of development. However, I don't like the contention that being unable to name something means you don't have a good grasp on what the component's function is. While that certainly can be true I often struggle with naming something that I have a very clear idea on its role, I just can't think of a snappy way to sum that functionality up.

Maybe I just have a bad vocabulary but in my experience most devs share this problem.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

Randomosity posted:

My co-worker is a really smart programmer and a great guy, but he is convinced empty lines make code ugly and hard to read.

:eng99:

Run all your source code through a minifier before checkin. It's not like the whitespace does anything anyway!

may not work for python

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

Melted_Igloo posted:

Dunno seems like the browser should scream some warning if the node path gets past like 20 levels, or at least there should be some plugin that does that

Rule #1 of web development: Browsers don't scream about *anything*.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

No Safe Word posted:

Which isn't because American English spells it that way, it's just because the RFC had it that way

It's poetic that a typo is literally built into the HTTP standard. I'm sure that says something profound about the Internet, though I'm not sure what.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

OddObserver posted:

It does. document.implementation.hasFeature. The actual feature granularity kinda sucks, though.

This is actually really frustrating when looking online to find the best way to detect a certain kind of browser. "Best practice" has taken over the web and virtually every site you find says "oh don't do browser detection, do feature detection".

Which is great if what you're trying to detect is whether a feature is supported or not. But despite the fact that we're in two-thousand-loving-eleven there are still behavioral differences between browsers that don't have anything to do with a DOM or script feature.

It's obnoxious that web dev conventional wisdom has decided these cases no longer crop up anymore.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost
Another input related one is Firefox notoriously caches input fields across multiple POSTs. This can be a huge pain in the rear end if, for example, dropdown selections determine a number of other JS-enhanced elements on the page and the drat events don't fire on reload in Firefox because the input fields are already "selected".

The workaround isn't difficult but it's a case where no "if (window.blah)" can solve the problem.

I've run into others involving subtleties in how some browsers fire off dependent HTTP requests when a user is navigating away from the current page; some browsers simply skip the request if it determines the response won't be useful. If you're trying to implement an internal JS analytics package that relies on sending that request it puts a rather sizable hole in your data aggregation and the only way to account for it is old-fashioned browser-sniffing :argh:

Dr Monkeysee fucked around with this message at 05:54 on May 18, 2011

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

Zombywuf posted:

I assume you've tried:
code:
Cache-Control: no-store, no-cache, max-age=0, must-revalidate
?

We tried everything we could possibly think of. We also confirmed it was an issue in other analytics packages (including Google Analytics, who actually warn in their documentation not to rely on this specific kind of event). It's not standard HTTP behavior, the request just never fires. Given the edge-case nature of it my guess is it's some weird "optimization" in the request/response loop someone decided was a good idea at some point.

Wheany posted:

So if you want to pretend that you support Opera, why would you check for Opera 5, and only Opera 5? It is literally over 10 years old and there are like 4 installations of it in existence on Windows 98 computers rotting on some attics somewhere.

What's particularly funny about this is Opera is literally the easiest browser to detect: if (window.opera).

Though I don't know if this property was available 10 years ago.

Dr Monkeysee fucked around with this message at 07:10 on May 19, 2011

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

Ensign Expendable posted:

code:
public boolean isTrue(boolean bool)
{
    return !Boolean.toString(bool).length()==5;
}

I've seen almost that in real-world code. It was something like

code:
    bool value = SomethingThatReturnsBool();
    if (value.ToString().ToLower() == "false")
    {
        ...
    }
Fortunately we caught that poo poo in a code review.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

BigRedDot posted:

At my last job the mish-mash of styles and conventions was so terrible that I eventually transcended past the point of ego. I would have adopted any scheme whatsoever, even if I personally hated it, so long as every loving one else did too.

This is something Microsoft did a really good job on with C#. They came out of the gate with a style-guide so any bullshit bracing arguments can just be trumped with "follow the MS standard". It (usually) works.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

Fren posted:

"No subclassing in Javascript? Oh well :("

The worst thing to happen to JavaScript was being born with a C-family syntax.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

pokeyman posted:

I've seen it argued that its C-like syntax helped it (or was necessary, even, to) get adopted everywhere, and it turns out it's not at all a bad language. I would've said the same thing as you a year ago, but I've changed my mind.

Well I was being glib to some degree.

I completely agree as to the reasons why it was given a C-like syntax. But it makes people think of it as a C-like language when it isn't. I think that's one of the reasons why JS didn't really come into its own until ~2006 or so, though again arguably it would have never caught on at all if not for its syntax.

Markov Chain Chomp posted:

javascript is a terrible language and youre only giving it the benfit of a doubt because it becomes ok once you bolt 3 frameworks on top of it

The general consensus these days is JavaScript is becoming the "assembler of the web".


Clavius posted:

code:
        </td>
    </tr>
</table>
Hey friend who is still living in 2002 web design land, you should consider a few more modern techniques. *Many links and hours of advice*

code:
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
:stare:

Hah, I recently had to implement a 3-column layout in CSS that could be flexible as to which column-ordering, width, etc, and the closing series of divs looks exactly like that. CSS is a horror from start to finish.


edit: I want to bitch about this more and the stairway of divs is a good illustration of that. CSS was a loving disaster the second it left the gate because for anything more complicated then a very basic document layout you have to add elements just to get the styling rules targeted correctly. So you end up with these horrible nested monstrosities just so you can get this float to relatively position itself next to that list or whatever.

Can you imagine if UI toolkits worked this way? That if you wanted to make a dialog button position itself in relation to the dialog message text you had to wrap it in 6 levels of panels or group boxes just to apply a series of esoteric positioning rules? They'd scrap that poo poo immediately.

There is a vast gap between the minimal semantic markup it takes to describe for example a news article with navigation menu and the actual markup you need so you can write the set of CSS rules that makes it look half-way decent. That's the very definition of a failed styling language and it should have been immediately obvious to anyone paying attention.

I loving hate CSS so much.

Dr Monkeysee fucked around with this message at 21:02 on Sep 16, 2011

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

Molog posted:

Good thing html 5 with javascript is going to be the next big thing.

All signs point to us entering a whole new generation of browser wars. I can't loving wait. I mean we *just* got IE on the same page as everybody and now everything's fragmenting again. Remember when Google was all about complying to standards?

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

BonzoESC posted:

It seems kind of nice to me, actually. Presuming I can put a main in an included file, I can put it at the top of the file, instead of jamming it in at the bottom or using some weird DOM event hooks to trigger it to start.

The problem is if Dart goes anywhere it'll likely be spread across multiple files just like JavaScript is. What if two files both include a main()? If it's truly an entry point then which one wins? If it's just shorthand for event-hookup then that's nice but it's not anything you can't already do.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

TasteMyHouse posted:

One from me, causing a bug I just found in my own code.

System.Diagnostics.StopWatch.ElapsedMilliseconds is VERY different from System.Diagnostics.StopWatch.Elapsed.Milliseconds

When I get curious as to how well some similar set of operations perform in a tight loop I'll whip up a really quick console app to give some rough metrics. Usually it's a single function that runs two or three loops, depending on how many operations I'm testing, and I always always forget to call StopWatch.Reset() between loops. I then waste my time trying to figure out why the hell operation2 is consistently twice as slow as operation1.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

Toady posted:

It's amusing how many times the developer claims something is fixed, followed by someone posting an exploit to prove it's not. I don't understand why he got mad at that Dan Rosenberg guy, other than bruised ego.

Yeah what the gently caress was up with kovid's "final warning" to Rosenberg? As far as I can tell Rosenberg's been cordial the entire thread.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

NotShadowStar posted:

My limited attempts at C# development made me realize that most testing frameworks were fragile hokey metaprogramming attempts that made debuggers really confused. The only testing framework that was worth a poo poo was ones that tried to avoid that and just mocked a new instance using the interface definition.

I ran into some weird edgecase in VS 2005 trying to determine how some unit test scaffolding was failing. You know all those attributes you use like [TestClass] and [TestMethod] and [TestCleanup]? Turns out MSTest does some hosed up syntactic analysis of the actual .cs file instead of using reflection to interrogate those attributes like any sane .NET code would.

I don't know if this is still true in VS 2008 or 2010 but that one blew my mind back then.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

PDP-1 posted:

The author of this book on C# insists on using Int32 everywhere instead of int because apparently having the shorter version defined in the language spec as 32 bits is not a good enough guarantee that it will actually be 32 bits wide. The keyword int can represent different width integers in other languages you see, so if you try to run your C# code through a COBOL compiler you may get errors.

That book is an ok read in general but the author spergs out about stuff constantly, sometimes to the point that the editor clearly moved big blocks of text into "Jeff's Ignorable Opinion" callout boxes just to preserve the reader's sanity.

He also pimps his own libraries constantly, sometimes to the detriment of explaining how the original thing his library replaces actually works under the hood which is the whole point of the book. It does have a couple really good chapters about threading though.

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

Smugdog Millionaire posted:

The advice I remember from the book was that you should make sure you name your methods as DoSomethingWithInt32 instead of DoSomethingWithInt because Int32 is a CLS type and int is a language keyword, not guaranteed to mean the same thing in another language calling your code.
Which is good advice that I agree with, but it isn't super important because I expect 100% of programmers targeting .NET to assume int=Int32.

He does say this and it's definitely good advice (in fact it's part of the Microsoft Framework Design Guidelines) but he also rails against the basic C# type keywords which is... okay I can kinda see his point but relax buddy.

There are quite a few portions of the book that swerve into "this is how I would have designed C# if somebody asked me and by the way I'd like to point out that no one asked me" territory. What's odd is I don't remember the second edition of the book having these weird asides; it was only the third edition after .NET 3.5 he apparently got all fussy about C# syntax.

Dr Monkeysee fucked around with this message at 23:49 on Nov 15, 2011

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

tef posted:

can anyone spot the bug in the binary search?


answer

This always struct me as a weird angle to take on this issue. When it was first pointed out back then it was sort of taken as a OH MY GOD EVERYTHING'S BEEN WRONG FOR DECADES. But in my experience well-worn algorithms like this are most often presented in an academic context which almost never includes error handling of any kind, let alone an architecture-specific overflow like this. Most of the time it's not even a specific language, it's just pseudocode.

It's like pointing out that Dijkstra's algorithm doesn't take into account dangling pointers or say how the graph is actually modeled. Well, yeah it doesn't because Dijkstra's algorithm doesn't assume it's running on any particular architecture or written in any particular language. Why is Binary Search any different?

I would presume that most real-world implementations of binary search buried in whatever framework libraries everyone was using would take these edge cases into account.

Dr Monkeysee fucked around with this message at 19:55 on Nov 17, 2011

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost
Sure that could be the case, but it's weird that this was presented as some fundamental flaw in the binary search algorithm, instead of just an inordinately widespread lazy implementation of it.

edit: and I don't mean that Joshua Bloch necessarily presented it like that but it was taken that way in the community as a whole. But this isn't like discovering the proof of Fermat's theorem has a flaw in it or unraveling Russel's set theory, it's just getting caught in the mismatch between the mathematical description of an algorithm and the real-world limitations of implementing it.

Dr Monkeysee fucked around with this message at 20:17 on Nov 17, 2011

Adbot
ADBOT LOVES YOU

Dr Monkeysee
Oct 11, 2002

just a fox like a hundred thousand others
Nap Ghost

Ender.uNF posted:

The real horror is MAX_PATH, a gift that will keep on giving.

I had Visual Studio fail to build a project due to a source tree that had too deep a directory structure. It was fine for a long time until I added one more subfolder that broke its back and suddenly it was failing the build as "12 of 12 projects built successfully; build failed". There was no error message in the build output even after turning on maximum verbosity. Just "everything built successfully; build failed." After reorganizing the folders to be less nested everything magically worked again.

This wasn't a Java project so I guess the horror was me.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply