Tag Info

New answers tagged

14

Your optimization wish (of transforming a sequence of if into the equivalent of a switch) makes sense only (as Jörg W Mittag wisely commented) for idempotent conditions (which are undecidable to detect in general). But we could restrict these conditions to be a disjunction of equality tests like x == k where x is always the same (SSA-form) simple scalar ...


0

The question you should be asking yourself is if the effort saved on maintenance (by not having to change code for future user requests) or the additional versatility (such as being able to easily convert and market the app to different users) are worth the additional effort of creating a more generalized system. Don't write a universal condiment dispensing ...


0

JDT's answer is pretty good, but another option you might want to consider is a domain-specific language (DSL). In this approach you define a simple language to capture your workflows, provide primitives for specialized checks and steps, etc., and then write an engine to interpret and execute them. By keeping everything in a database, or hard-coded, you ...


3

I can think of two possible solutions here, but they both require a fair amount of development (but I really can't see a solution where this is not the case). I would also recommend not developing any specific kind of check step until it is actually needed. It's very easy to have requirements for 42 different kinds of automated steps that end up having only ...


2

A real-world example: I had a web application that made use of a very large set of data that rarely changed and which needed to be accessed very quickly (quick enough for per-keystroke response via AJAX). The obvious enough thing to do here is to load the relevant graph into memory, and access it from there rather than the database, updating the graph when ...


1

I have a usage for garbage disposal which is somewhat unorthodox. There is this misguided practice which is unfortunately very prevalent in the C# world, of implementing object disposal using the ugly, clunky, inelegant, and error prone idiom known as IDisposable-disposing. MSDN describes it in length, and lots of people swear by it, follow it religiously, ...


10

One thing no one has mentioned is that, while the Windows GC is amazingly good, the GC on Xbox is garbage (pun intended). So when coding an XNA game intended to run on XBox, it's absolutely crucial to time garbage collection to opportune moments, or you'll have horrible intermittent FPS hiccups. Additionally, on XBox it's common to use structs way, way ...


4

Garbage collection is first and foremost a memory management tool. As such, garbage collectors will collect when there is memory pressure. Modern garbage collectors are very good, and getting better, so it's unlikely that you can improve on them by collecting manually. Even if you can improve things today, it may well be that a future improvement to your ...


2

The best practise is to not force a garbage collection in most cases. (Every system I have worked on that had forced garbage collections, had underlining problems that if solved would have removed the need to forced the garbage collection, and speeded the system up greatly.) There are a few cases when you know more about memory usage then the garbage ...


56

Sadly, nobody there elaborates on what are such cases. I'll give some examples. All in all it is rare that forcing a GC is a good idea but it can be totally worth it. This answer is from my experience with .NET and GC literature. It should generalize well to other platforms (at least those that have a significant GC). Benchmarks of various kinds. You ...


2

There are several cases where you might want to call gc() yourself. [Some people say that this is not good because it may promote objects to older generation space which I agree is not a good thing. However, it is NOT always true that there will always be objects which can be promoted. It is certainly possible that after this gc() call, very few objects ...


97

You really can't make blanket statements about appropriate way to use all GC implementations. They vary wildly. So I'll speak to the .NET one which you originally referred to. You must know the behaviour of the GC pretty intimately to do this with any logic or reason. The only advice on collection I can give is: Never do it. If you truly know the ...


26

As a general principle, a garbage collector will collect when it runs into "memory pressure", and it's considered a good idea to not have it collect at other times because you could cause performance problems or even noticeable pauses in your program's execution. And in fact, the first point is dependent on the second: for a generational garbage collector, ...


0

Because there's absolutely no value whatsoever in making a special character for every random constant you can come up with. There are far too many and their uses come up far too little. Should there also be a special character for "MAX_VALUE - 1"? How about "MAX_VALUE - 2"? Frankly, using arbitrary maximum values is an annoying code smell, and finding ...


4

Language consistency The discoverability of the actual constant to use in a given language is not a big deal either. I've never used this constant in Java, but a simple Google search for "java int max value" leads to Integer.MAX_VALUE just by glimpsing on the Google results, without even opening any additional page. How fast is that? More importantly, the ...


0

So far here are some ways decimal Unicode can be specified enough to convey the meaning to anyone who searches: XML Entity Notation: &#nnn; C / C++ Wide Character: wchar_t(nnn) SQL National Character: NCHAR(nnn) (Available in MSSQL, MySQL, Oracle) Windows ALT Notation: ALT+nnn (although it can be easily confused with the hex version with the plus key, ...


3

There is no commonly accepted decimal notation for Unicode codepoints. Unicode codepoints are almost universally represented in hexadecimal. The sole exception I'm aware of is the use of Numeric Character References (NCRs) in languages derived from SGML (e.g., HTML and XML), which can take one of two forms: &#nnn; in decimal or &#xnnn; in ...


2

I assume, that you want the simplest, clearest algorithm. In this case, knowing that filter c is always applied, I would live it out of the if logic and apply it at the end regardless. As it looks in your flowchart, each filter before the c, is optional, because each of them can either be applied, or not. In this case, I would live ifs separate from each ...


19

You haven't said whether the filters take any parameters. For example, filter_A might be a category filter, so that it's not just a question of "do I need to apply filter_A", it could be "I need to apply filter_A and return all records in with the category field = fooCategory". The simplest way to implement exactly what you've described (but make sure to ...


0

I wonder if modeling your filters to be some kind of objects in a graph would make sense. At least that's what I think of when seeing the diagram. If you model the dependency of the filters like a object graph, then the code that handles the possible flow paths is pretty much straight forward without any hairy logic. Also, the graph (business logic) can ...


3

In this case, it is important to separate the logic of filtering, and the control flow of how the filters run. The filter logic should be separated out into individual functions, that can run independent of each other. ApplyFilterA(); ApplyFilterB(); ApplyFilterC(); In the sample code posted, there's 3 booleans filter_A, filter_B, and filter_C. However, ...


1

I'm going to assume filterA, filterB, and filterC actually modify the list of products. Otherwise, if they are just if-checks, then filterA and filterB can be ignored since all paths lead ultimately to filterC. Your description of the requirement seems to imply that each filter will reduce product list. So assuming the filters actually reduce the list of ...


0

You indicated that you don't want to do row/column traversal, but that could be a useful method. Calculate an index change value for the array so each new index translates into a row/column position that samples a different area of the matrix. The only requirement is that the index change value must be coprime with the array length. This guarantees that each ...


3

For what its' worth, the article you linked was discussing people who write promise libraries, not people who use them. Your use case seems a bit larger than typical, but as far as I can tell from your description, it's a relatively good fit for promises. Promises are designed to simplify sequencing and composition of asynchronous code. That's certainly ...



Top 50 recent answers are included