readability

How to find good looking font color if background color is known? [closed]

霸气de小男生 提交于 2019-11-27 09:00:22
问题 There seem to be so many color wheel, color picker, and color matcher web apps out there, where you give one color and the they'll find a couple of other colors that will create a harmonic layout when being used in combination. However most of them focus on background colors only and any text printed on each background color (if text is printed at all in the preview) is either black or white. My problem is different. I know the background color I want to use for a text area. What I need help

New (std::nothrow) vs. New within a try/catch block

耗尽温柔 提交于 2019-11-27 07:57:39
I did some research after learning new , unlike malloc() which I am used to, does not return NULL for failed allocations, and found there are two distinct ways of checking whether new had succeeded or not. Those two ways are: try { ptr = new int[1024]; } catch(std::bad_alloc& exc) { assert(); }; and ptr = new (std::nothrow) int[1024]; if(ptr == NULL) assert(); I believe the two ways accomplish the same goal, (correct me if I am wrong of course!), so my question is this: which is the better option for checking if new succeeded, based entirely on readability, maintainability, and performance,

Should java try blocks be scoped as tightly as possible?

天大地大妈咪最大 提交于 2019-11-27 06:40:21
I've been told that there is some overhead in using the Java try-catch mechanism. So, while it is necessary to put methods that throw checked exception within a try block to handle the possible exception, it is good practice performance-wise to limit the size of the try block to contain only those operations that could throw exceptions. I'm not so sure that this is a sensible conclusion. Consider the two implementations below of a function that processes a specified text file. Even if it is true that the first one incurs some unnecessary overhead, I find it much easier to follow. It is less

Reference equality performance difference? ((object)obj1 == (object)obj2) vs. object.ReferenceEquals( obj1, obj2 )

99封情书 提交于 2019-11-27 03:48:47
问题 Is there extra overhead in using the object.ReferenceEquals method verses using ((object)obj1 == (object)obj2) ? In the first case, there would be a static method call involved, and in both cases some form of casting to an object would be involved. Even if the compiler balances out those methods, what about inequality? (object)obj != null as compared to... !object.ReferenceEquals(obj,null) I suppose that at some point, a logical negation would occur, either within the != operator, or as

Java try/catch performance, is it recommended to keep what is inside the try clause to a minimum?

[亡魂溺海] 提交于 2019-11-27 00:56:57
Considering you have code like this: doSomething() // this method may throw a checked a exception //do some assignements calculations doAnotherThing() //this method may also throw the same type of checked exception //more calls to methods and calculations, all throwing the same kind of exceptions. Now I know, there is in fact a performance hit when constructing the exception, specifically unwinding the stack. And I have also read several articles pointing to a slight performance hit when entering try/catch blocks, but none of the articles seem to conclude anything. My question is, is it

`if key in dict` vs. `try/except` - which is more readable idiom?

非 Y 不嫁゛ 提交于 2019-11-27 00:45:42
I have a question about idioms and readability, and there seems to be a clash of Python philosophies for this particular case: I want to build dictionary A from dictionary B. If a specific key does not exist in B, then do nothing and continue on. Which way is better? try: A["blah"] = B["blah"] except KeyError: pass or if "blah" in B: A["blah"] = B["blah"] "Do and ask for forgiveness" vs. "simplicity and explicitness". Which is better and why? Exceptions are not conditionals. The conditional version is clearer. That's natural: this is straightforward flow control, which is what conditionals are

Implicit return values in Ruby

↘锁芯ラ 提交于 2019-11-26 22:57:27
问题 I am somewhat new to Ruby and although I find it to be a very intuitive language I am having some difficulty understanding how implicit return values behave. I am working on a small program to grep Tomcat logs and generate pipe-delimited CSV files from the pertinent data. Here is a simplified example that I'm using to generate the lines from a log entry. class LineMatcher class << self def match(line, regex) output = "" line.scan(regex).each do |matched| output << matched.join("|") << "\n"

Why are “continue” statements bad in JavaScript? [closed]

血红的双手。 提交于 2019-11-26 22:51:59
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 months ago . In the book Javascript: The Good Parts by Douglas Crockford, this is all the author has to say about the continue Statement: The continue statement jumps to the top of the loop. I have never seen a piece of code that was not improved by refactoring it to remove the continue

Is while (true) with break bad programming practice?

六眼飞鱼酱① 提交于 2019-11-26 20:19:34
I often use this code pattern: while(true) { //do something if(<some condition>) { break; } } Another programmer told me that this was bad practice and that I should replace it with the more standard: while(!<some condition>) { //do something } His reasoning was that you could "forget the break" too easily and have an endless loop. I told him that in the second example you could just as easily put in a condition which never returned true and so just as easily have an endless loop, so both are equally valid practices. Further, I often prefer the former as it makes the code easier to read when

Should a developer aim for readability or performance first? [closed]

偶尔善良 提交于 2019-11-26 19:49:20
Oftentimes a developer will be faced with a choice between two possible ways to solve a problem -- one that is idiomatic and readable, and another that is less intuitive, but may perform better. For example, in C-based languages, there are two ways to multiply a number by 2: int SimpleMultiplyBy2(int x) { return x * 2; } and int FastMultiplyBy2(int x) { return x << 1; } The first version is simpler to pick up for both technical and non-technical readers, but the second one may perform better, since bit shifting is a simpler operation than multiplication. (For now, let's assume that the