readability

System.out.println() vs \\n in Java

老子叫甜甜 提交于 2019-11-30 04:00:33
Let's say I wanted to print 5 lines. Which is the best method (for performance and readability). System.out.println(); System.out.println(); System.out.println(); System.out.println(); System.out.println(); or System.out.println("\n\n\n\n"); Is it a matter of preference or is one better than the other. It seems like it would save a lot of time using the second method. There is a functional difference between the two. The first version outputs line breaks using the platform's preferred line separator. The second version outputs newline characters, which is likely to be inappropriate on Windows

How do I write more maintainable regular expressions?

北城余情 提交于 2019-11-29 19:12:52
I have started to feel that using regular expressions decreases code maintainability. There is something evil about the terseness and power of regular expressions. Perl compounds this with side effects like default operators. I DO have a habit of documenting regular expressions with at least one sentence giving the basic intent and at least one example of what would match. Because regular expressions are built up I feel it is an absolute necessity to comment on the largest components of each element in the expression. Despite this even my own regular expressions have me scratching my head as

Why STL implementation is so unreadable? How C++ could have been improved here?

让人想犯罪 __ 提交于 2019-11-29 15:57:42
问题 For instance why does most members in STL implementation have _M_ or _ or __ prefix? Why there is so much boilerplate code ? What features C++ is lacking that would allow make vector (for instance) implementation clear and more concise? 回答1: Implementations use names starting with an underscore followed by an uppercase letter or two underscores to avoid conflicts with user-defined macros. Such names are reserved in C++. For example, one could define a macro called Type and then #include

“public static” or “static public”?

强颜欢笑 提交于 2019-11-29 11:06:56
问题 A minor point about function declaration keywords in PHP: If you've got a class method that's static, should the static keyword come before or after the visibility keyword ( public , protected , private )? Assuming all your methods, static or otherwise, have a visibility keyword, then you'd want the visibility keyword to remain in the same place relative to the function keyword: public function foo() {} public function bar() {} protected function baz() {} private function quux() {} Now

Making large constants in C source more readable?

只谈情不闲聊 提交于 2019-11-29 10:22:15
I'm working on some code for a microprocessor. It has a few large, critical constants. #define F_CPU 16000000UL In this case, this is the CPU frequency. In Hertz. As it is, it's rather hard to tell if that's 1,600,000, 160,000,000 or 16,000,000 without manually tabbing a cursor across the digits. If I put commas in the number #define F_CPU 16,000,000UL , it truncates the constant. I've worked with a few esoteric languages that have a specific digit-separator character, intended to make large numbers more readable (ex 16_000_000 , mostly in languages intended for MCUs). Large "magic numbers"

Would you use num%2 or num&1 to check if a number is even?

我们两清 提交于 2019-11-29 09:09:14
Well, there are at least two low-level ways of determining whether a given number is even or not: 1. if (num%2 == 0) { /* even */ } 2. if ((num&1) == 0) { /* even */ } I consider the second option to be far more elegant and meaningful, and that's the one I usually use. But it is not only a matter of taste; The actual performance may vary: usually the bitwise operations (such as the logial-and here) are far more efficient than a mod (or div) operation. Of course, you may argue that some compilers will be able to optimize it anyway, and I agree...but some won't. Another point is that the second

Improving Code Readability [closed]

 ̄綄美尐妖づ 提交于 2019-11-28 17:16:14
When it comes to code documentation, it is usually accepted that code should explain itself , and inline code documentation (excluding public API documentation) should only explain meta-code issues such as workarounds, explanations on why specific implementations were chosen, etc. How do you accomplish making your code more readable and more explaining itself ? Edit: in addition to general comments, I'm also looking for specific tips. So if you say "short but meaningful variable names", it would be nice to also get a helpful tip as well (e.g. "use the three-word principle"). cletus Check out

Boolean method naming readability

拥有回忆 提交于 2019-11-28 16:26:52
Simple question, from a readability standpoint, which method name do you prefer for a boolean method: public boolean isUserExist(...) or: public boolean doesUserExist(...) or: public boolean userExists(...) public boolean userExists(...) Would be my prefered. As it makes your conditional checks far more like natural english: if userExists ... But I guess there is no hard and fast rule - just be consistent Kai I would say userExists , because 90% of the time my calling code will look like this: if userExists(...) { ... } and it reads very literally in English. if isUserExist and if

Generic Exception Handling in Python the “Right Way”

瘦欲@ 提交于 2019-11-28 15:45:24
问题 Sometimes I find myself in the situation where I want to execute several sequential commands like such: try: foo(a, b) except Exception, e: baz(e) try: bar(c, d) except Exception, e: baz(e) ... This same pattern occurs when exceptions simply need to be ignored. This feels redundant and the excessive syntax causes it to be surprisingly difficult to follow when reading code. In C, I would have solved this type of problem easily with a macro, but unfortunately, this cannot be done in straight

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

放肆的年华 提交于 2019-11-28 15:05:45
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 with is choosing a couple of colors (the more, the merrier) I can use as font colors on this background