coding-style

Mandatory use of braces

对着背影说爱祢 提交于 2019-12-04 17:12:22
问题 As part of a code standards document I wrote awhile back, I enforce "you must always use braces for loops and/or conditional code blocks, even (especially) if they're only one line." Example: // this is wrong if (foo) //bar else //baz while (stuff) //things // This is right. if (foo) { // bar } else { // baz } while (things) { // stuff } When you don't brace a single-line, and then someone comments it out, you're in trouble. If you don't brace a single-line, and the indentation doesn't

Programmers dictionary/lexicon for non native speakers

霸气de小男生 提交于 2019-12-04 17:04:09
问题 I'm not an English speaker, and I'm not very good at English. I'm self thought. I have not worked together with others on a common codebase. I don't have any friends who program. I don't work with other programmers (at least nobody who cares about these things). I guess this might explain some of my problems in finding good unambiguous class names. I have tried to find some sort of "Programmers dictionary" containing words often used and their meanings. When reading others code I have to look

Tips for coding using hostile tools? [closed]

Deadly 提交于 2019-12-04 17:03:45
问题 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 last year . I am developing an application using the wrong tools. I don't wish to get into the rights or wrongs of this - the platform has been blessed as Strategic and nothing is going to change that now. But I'm hoping somebody can give me some tips on how to make the best of the

Is GetLastError() kind of design pattern? Is it good mechanism?

◇◆丶佛笑我妖孽 提交于 2019-12-04 16:54:27
问题 Windows APIs uses GetLastError() mechanism to retrieve information about an error or failure. I am considering the same mechanism to handle errors as I am writing APIs for a proprietary module. My question is that is it better for API to return the error code directly instead? Does GetLastError() has any particular advantage? Consider the simple Win32 API example below: HANDLE hFile = CreateFile(sFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile =

“Double” assignment - should it be avoided?

跟風遠走 提交于 2019-12-04 16:48:38
问题 Consider you have some expression like i = j = 0 supposing this is well-defined in your language of choice. Would it generally be better to split this up into two expressions like i = 0 j = 0 I see this sometimes in library code. It doesn't seem buy you much in terms of brevity and shouldn't perform any better than the two statements (though that may be compiler dependant). So, is there a reason to use one over the other? Or is it just personal preference? I know this sounds like a silly

How to minimize use of arrow keys when typing code?

吃可爱长大的小学妹 提交于 2019-12-04 16:35:03
问题 When typing code, I would normally close brackets, go back inside, go outside, type semicolon, etc: I might start with (| is the caret): System.out.println()| Then go left: System.out.println(|) Then this: System.out.println(foo()|) Again backtracking a space: System.out.println(foo(|)) Typing quotes are similar: System.out.println(foo(""|)) ...etc. My right hand is constantly moving between the home row and the arrow keys. I've tried vim and although I know the basics, it still feels very

Are there any published coding style guidelines for SQL?

偶尔善良 提交于 2019-12-04 16:24:29
问题 Often I will end up with very complex SQL statements and I wondered if there was style guideline out there that dictates a common way of laying various aspects of a query out. I am look for something descriptive along the lines of Python's PEP8 or Zend Frameworks guidelines and not code by example. Most of my queries are written for MySQL. So do you know of a universal style guide? Perhaps you have written one yourself. Please share your guidelines. 回答1: Since asking this question I have

Java PMD warning on non-transient class member

情到浓时终转凉″ 提交于 2019-12-04 16:11:11
问题 On line: private boolean someFlag; I get the following PMD warning: Found non-transient, non-static member. Please mark as transient or provide accessors. Can someone please explain why this warning is there and what it means? (I understand how to fix it, I don't understand why it's there...) I'm getting this on many other member declarations as well... EDIT: My class is definitely not a bean, and not serializable... 回答1: I assume your class is a bean that by definition implements

Why does the standard C++ library use all lower case?

时间秒杀一切 提交于 2019-12-04 15:25:51
问题 Just curious why the C++ standard library uses all lower case and underscores instead of camelCase or PascalCase naming convention. Personally, I find the latter much easier to deal with when typing out code, but is there some kind of legitimate reason to use the former? 回答1: Main reason : To keep compatibility with the existing code, since they have done it with C also. Also have a look at these C++ Coding standards, which presents some generic reasoning regarding the importance of

JavaDoc: where to add notes/remarks to documentation?

核能气质少年 提交于 2019-12-04 14:59:20
问题 When coding in C# I have always found the tag remarks very useful for providing notes about the implementation of a class or method, or to give information about the theory of what I was implementing. I am now using Java but I can't find an appropriate JavaDoc tag for this. Maybe in Java you accomplish this in a different manner, does anybody know? 回答1: As far as I know, there isn't any dedicated Javadoc tag for notes or remarks. Generally, the first sentence of Javadoc should give a brief