196 reputation
5
bio website
location Redmond, WA
age
visits member for 3 years, 2 months
seen yesterday

Aug
19
comment How to change the state of a singleton in runtime
Initialization of the file link needs to be one of the first things your app does - otherwise you may end up calling log before there's an output file (a good library probably has a built-in buffer or at least a default destination file). If you're building a GUI app, you can probably do it before the launch of the UI via the Swing threads. Most servers come with the logging built-in, so it's not something you have to worry about.
Aug
19
comment How to change the state of a singleton in runtime
synchronized, while it will make things thread-safe, is likely to slow logging significantly (waiting for other threads). Depending on the design, you might even get into some form of deadlock, which would be extremely painful. Besides which, it wouldn't actually protect you from the biggest issue - calling log before setFile.
Aug
8
comment How to make sure media are used only on authorised sites?
The moment you serve the video, people can record it (you're providing them the data feed). There's ways to make this more difficult (isn't there some media encryption proposed for HTML5?), but there's too many ways to "recover" the data on a PC. You're trying to create your own DRM library/scheme/deployment, whereas the big name entertainment companies have spent millions (or billions) of dollars and failed in the long term (and generally just annoyed legitimate users). There's likely a library for baseline protection, but you can't stop determined people.
Aug
7
comment Eliminate duplicate code in nested IFs without creating a function
... why do you want to avoid a function? That's one of the things they're meant to do - keep you from writing the same thing multiple times. As the accepted answer shows it can be mitigated here, but the fact that you're avoiding a reasonable tool is somewhat troubling.
Jul
3
comment Why does C# have much more features than Java?
Note that Java probably has a greater selection of 3rd party libraries, likely by an order of magnitude.
Jun
27
comment Algorithm for percentage without knowing total number
After line 1 gets 6 calls, give line 2 4 calls. That is, don't care about the actual total count, care about the distribution over the "period" (10, in this case) that you do know. Obviously you can do stuff like alternate lines except the last value, so there isn't a strict wait necessary either. If there's some sort of queue, do the percentage based on current rows in the queue.
Jun
24
comment C# server side application 100 GB dataset + Garbage Collection
I'd put it in a DB, too. For that matter, there are some in-memory dbs, dunno if they could handle something that size though.
May
23
comment Origins of code indentation
Barring cases where indentation is used to change the semantic meaning of code (that is, where changing indentation will put it in loops or as part of an if, a la F#), indentation isn't really a language feature, it's an IDE feature (and a bit in the compiler, to ignore leading spaces). @Jack's right - originally programs were punched on cards, and indentation literally didn't exist in the storage (and perhaps shouldn't now, either). Columnar RPG doesn't use indentation (and you only have ~20 characters free per line anyways), but the IDE can "soft" indent the code for you.
May
23
comment Origins of code indentation
I don't think the quoted text actually supports the use/existence of indentation. That's support for sectioning code. Java uses brackets ({}) to delimit blocks, and you can define nested functions, but that doesn't tell me anything about whether the code is actually indented.
May
23
comment What's the copyright status of boilerplate code?
The fewer lines of code needed to complete a task, the likelier that different original implementations will be the same. If asked to sum all elements in an array, pretty much everybody is going to use a loop with an externally defined variable to hold the running total. There's two major directions to take a factorial function. The code submitted for things like Code Chef might be interesting to examine here - for all distinct (correct!) results, run a diff.
May
17
comment Using a Simple/Static Factory vs. instantiating directly: new Thing() vs. factory.createThing() - what's the benefit?
Of course, now it's generally frowned on to use a static factory in favor of an injected one. Factories allow instantiation to use caches if the language doesn't support it natively. It'd also allow for parameter checking without starting object instantiation. Some stuff might be language dependent...
May
4
comment Is “poaching” an acceptable way to get open-source volunteers?
Problem #1 - Intellectual Property. If you get a guy from Adobe to write part of your video-editing software, what happens if he includes something from Premier? Adobe'd be able to sue your project into oblivion. Some companies have developers sign contracts saying that everything they develop during employment belongs to their employer, to avert some related edge cases (enforceability varies by locale, though). At minimum, it'd usually be considered extremely bad form to compete against your current employer...
Feb
10
comment equals and hashcode methods autogenerated, is it always a good practice?
Thankfully, Apache commons at least also exposes a manual interface. Beyond that, even if you don't use the classes that way somebody else might - anything that might conceivably be a value type should have those methods (plus toString()). There are a number of things that don't need them, often cases where you only need one instance period. Perhaps you could give a specific example?
Feb
9
comment How far to go when standardizing code
Code debt, like with other assets, has interest - it'll get worse over time unless you actively work to reduce it; this is easier the earlier you start. Hopefully, you have a set of tests you can use to ensure you don't break your code - if not, that's the first step. Clean up everything you can, to whatever standard your team has decided on.
Feb
8
comment Good idea to put bug numbers in a comment in the beginning of the source file?
I've worked at a place where they did essentially this (including logging who made the change, and project number, even though that was present in the source control system). On some files this got to be as long as the actual source code (or a significant portion thereof). Oh, and the format had changed multiple times, and some of the comments made reference to things that no longer applied... Didn't help that this was RPG, and we were using Turnover. I was much happier when we moved to Java and SVN, and left that behind us.
Dec
8
comment Storing a mailing address in a database: What structure should I use for International apps?
Well, here's hoping no address has zip-code-looking data from another country! Although the larger problem is that on databases of any size, this would ignore indices... which is why, like you say, they should be in separate fields.
Dec
8
comment Storing a mailing address in a database: What structure should I use for International apps?
... And what 'simple logic' would allow you to determine what the zip-code is from a single blob? American zip-codes are 5 digits (9, actually), and are placed at the end of an address; Canadian zip-codes are of the form A0A 0A0, and placed at the end; Japanese zip-codes are 7 digits, and usually placed at the start: At minimum, you're going to want to store the country (although that has political issues), if only to know what the format should be. For performance reasons, anything you search/sort by should be in a separate field, at which point you should probably break it apart...
Oct
29
comment Advice on designing web application with a 40+ year lifetime
While I'll grant that EAVs can be used, you'd be surprised at the relationships you can find. That said, the extra attributes that often show up for these kinds of industries (healthcare, customer relations, etc) do have to go somewhere... Just make sure to back it with an attribute-key table, to get a canonical list of attributes.
Oct
29
comment Advice on designing web application with a 40+ year lifetime
Or even if you're using the same vendor, newer versions may change db-specific stuff, whereas the standard is usually a bit more stable
Sep
21
comment Correct comment to put for boolean function arguments that are “false”?
@Bakuriu - actually, I'd probably still have the public API have two separate methods (sortAscending and sortDescending, or similar). Now, inside, they may both call the same private method, which might have this kind of parameter. Actually, if the language supported it, probably what I'd pass in would be a lambda function that contained the sorting direction...