code-formatting

Checking for NULL pointer in C/C++ [closed]

為{幸葍}努か 提交于 2019-11-26 06:58:46
问题 In a recent code review, a contributor is trying to enforce that all NULL checks on pointers be performed in the following manner: int * some_ptr; // ... if (some_ptr == NULL) { // Handle null-pointer error } else { // Proceed } instead of int * some_ptr; // ... if (some_ptr) { // Proceed } else { // Handle null-pointer error } I agree that his way is a little more clear in the sense that it\'s explicitly saying \"Make sure this pointer is not NULL\", but I would counter that by saying that

How do I format XML in Notepad++?

天大地大妈咪最大 提交于 2019-11-26 06:51:13
问题 I have Notepad++ and I got some XML code which is very long. When I pasted it in Notepad++ there was a long line of code (difficult to read and work with). I want to know if there is a simple way to make the text readable (by readable I mean properly tabbed code). I can do it manually, but I want a permanent solution to this as I have faced this several times. I am sure there is a way to do this as I have done it once before a couple of years back, maybe with Visual Studio or some other

How can I break up this long line in Python?

一个人想着一个人 提交于 2019-11-26 06:13:47
问题 How would you go about formatting a long line such as this? I\'d like to get it to no more than 80 characters wide: logger.info(\"Skipping {0} because its thumbnail was already in our system as {1}.\".format(line[indexes[\'url\']], video.title)) Is this my best option? url = \"Skipping {0} because its thumbnail was already in our system as {1}.\" logger.info(url.format(line[indexes[\'url\']], video.title)) 回答1: That's a start. It's not a bad practice to define your longer strings outside of

How to auto-format code in Eclipse?

萝らか妹 提交于 2019-11-26 06:09:51
问题 How do you auto-format code in Eclipse? 回答1: On Windows and Linux : Ctrl + Shift + F On Mac : ⌘ + ⇧ + F (Alternatively you can press Format in Main Menu > Source) 回答2: Another option is to go to Window->Preferences->Java->Editor->SaveActions and check the Format source code option. Then your source code will be formatted truly automatically each time you save it. 回答3: CTRL + SHIFT + F will auto format your code(whether it is highlighted or non highlighted). 回答4: This can also be done at the

Turn off auto formatting in Visual Studio

假装没事ソ 提交于 2019-11-26 06:00:26
问题 I\'m a code purist, preferring my own style of code formatting as opposed to Visual Studio\'s default settings. I\'ve turned off auto-formatting options in Tools/options. In most cases it works. After using any of the built-in refactorings, Visual Studio clobbers my settings with its default settings. How do I keep VS from doing that? 回答1: I had this problem while writing VB in an aspx page. The solution was to go to 'Tools > Options > Text Editor > Basic > VB Specific' and turn 'Pretty

Unnecessary curly braces in C++?

假装没事ソ 提交于 2019-11-26 05:57:26
问题 When doing a code review for a colleague today I saw a peculiar thing. He had surrounded his new code with curly braces like this: Constructor::Constructor() { existing code { New code: do some new fancy stuff here } existing code } What is the outcome, if any, from this? What could be the reason for doing this? Where does this habit come from? Edit: Based on the input and some questions below I feel that I have to add some to the question, even though that I already marked an answer. The

How to disable code formatting for some part of the code using comments?

核能气质少年 提交于 2019-11-26 04:36:18
问题 I\'d like to selectively disable the IntelliJ IDEA code formatter for a portion of code just like I can in Eclipse. Does IntelliJ support this feature, and if so, how do I use it? 回答1: Since version 13 it's possible to wrap the code with // @formatter:off ... // @formatter:on In versions 2016.x enable it in Preferences > Editor > Code Style . (Thanks Philipe) In version 2018.x enable it in File > Settings > Editor > Code Style (you can change the formatter control markers, as long as they're

Code formatting shortcuts in Android Studio for Operation Systems

核能气质少年 提交于 2019-11-26 04:29:04
问题 I have started developing with Android Studio. In Eclipse I was using Ctrl + Shift + F , but in Android Studio it does not work. It will be different. How can I jump to any method in a .java file? I was using Ctrl + O in Eclipse. Is it available? What is the shortcut for code formatting? 回答1: Windows: Ctrl + Alt + L Linux: Ctrl + Shift + Alt + L macOS: Option + Command + L Reference: Key Commands and here are all of the commands for Windows/ Linux users and for Mac users. As Rohit faced a

How to turn off the Eclipse code formatter for certain sections of Java code?

﹥>﹥吖頭↗ 提交于 2019-11-26 03:15:07
问题 I\'ve got some Java code with SQL statements written as Java strings (please no OR/M flamewars, the embedded SQL is what it is - not my decision). I\'ve broken the SQL statements semantically into several concatenated strings over several lines of code for ease of maintenance. So instead of something like: String query = \"SELECT FOO, BAR, BAZ FROM ABC WHERE BAR > 4\"; I have something like: String query = \"SELECT FOO, BAR, BAZ\" + \" FROM ABC \" + \" WHERE BAR > 4 \"; This style makes the

Stand-alone Java code formatter/beautifier/pretty printer? [closed]

a 夏天 提交于 2019-11-26 03:07:12
问题 I\'m interested in learning about the available choices of high-quality, stand-alone source code formatters for Java. The formatter must be stand-alone, that is, it must support a \"batch\" mode that is decoupled from any particular development environment. Ideally, it should be independent of any particular operating system as well. So, a built-in formatter for the IDE du jour is of little interest here (unless that IDE supports batch mode formatter invocation, perhaps from the command line)