coding-style

Set Vim's shiftwidth and tabstop based on directory

霸气de小男生 提交于 2019-12-20 10:38:23
问题 I have a project I'm working on currently where the coding standard is to use 2 space indentation. On other projects, however, I use 4 space indentation. Is there an easy way to tell vim that all files within a certain directory should have a tabstop of 2 spaces? 回答1: The venerable Tim Pope just released a plugin call Sleuth, which automagically determines shiftwidth and tabstop (among other buffer options) based on what's used in the current file (or, incredibly, if it's a new buffer, based

emacs 23 python.el auto-indent style — can this be configured?

自作多情 提交于 2019-12-20 10:37:05
问题 I have been using emacs 23 (python.el) for just over a month now and I'm unhappy with the default auto-indentation settings. Currently, my Python files are auto-indented as follows: x = a_function_with_dict_parameter({ 'test' : 'Here is a value', 'second' : 'Another value', }) a_function_with_multiline_parameters(on='First', line='Line', now_on='Second', next_line='Line', next='Third', finally='Line') I would prefer if I could set the auto-indentation settings so the same code could easily be

How to comment/uncomment in HTML code

為{幸葍}努か 提交于 2019-12-20 10:23:17
问题 Often while coding view templates in html, my habit of adding some helpful comments causes lots of time-consuming effort while testing. Consider this code... <!-- Here starts the sidebar --> <div id="sidebar"> .... </div> <!-- Here starts the main contents pane --> <div id="main-contents"> ... </div> <!-- Here starts the footer --> <div id="footer"> ... </div> Now, if I have to hide out some portion of the view template, in case of php I would just select the desired code and put single-line

Why is indentation in empty lines bad?

巧了我就是萌 提交于 2019-12-20 10:18:50
问题 Every FOSS project I know has rules against trailing whitespace in code. But I think it's very natural to continue the current indentation on the next line: int main() { ....int a = 42; .... ....return a; } But git for instance throws warnings anyway. So my question is: Why are those tabs inside the current indentation bad? I'm not looking for answers like "It's always done this way". Let's assume indentation is done consistently in the whole project in question. 回答1: It is probably because

PHP Coding styles return; in switch/case

被刻印的时光 ゝ 提交于 2019-12-20 10:14:51
问题 we're trying to implement new coding style guidelines for our team, the php codesniffer is printing an warning on switch case statements when no "break" is found like: switch ($foo) { case 1: return 1; case 2: return 2; default: return 3; } is there any good reason to use : switch ($foo) { case 1: return 1; break; } ?? the break is never reached ? 回答1: It's perfectly valid to leave out the break when you return from a switch . But it's fairly common practise to add explicit break s to every

Is there a style checker for c++?

偶尔善良 提交于 2019-12-20 10:11:02
问题 I have worked with java for a while now, and I found checkstyle to be very useful. I am starting to work with c++ and I was wondering if there is a style checker with similar functionality. I am mainly looking for the ability to write customized checks. 回答1: What about Vera++ ? Vera++ is a programmable tool for verification, analysis and transformation of C++ source code. Vera++ is mainly an engine that parses C++ source files and presents the result of this parsing to scripts in the form of

Impact on style of GHC -Wall

感情迁移 提交于 2019-12-20 09:53:09
问题 It is considered good practice to enable GHC warnings with -Wall . However, I've found out that fixing those warnings has a negative effect for some types of code constructs. Example 1: Using the do-notation equivalent of f >> will generate a warning if I don't explicitly use the _ <- f form: Warning: A do-notation statement discarded a result of type Char. Suppress this warning by saying "_ <- f", or by using the flag -fno-warn-unused-do-bind I understand that I can forget to do something

Impact on style of GHC -Wall

独自空忆成欢 提交于 2019-12-20 09:50:59
问题 It is considered good practice to enable GHC warnings with -Wall . However, I've found out that fixing those warnings has a negative effect for some types of code constructs. Example 1: Using the do-notation equivalent of f >> will generate a warning if I don't explicitly use the _ <- f form: Warning: A do-notation statement discarded a result of type Char. Suppress this warning by saying "_ <- f", or by using the flag -fno-warn-unused-do-bind I understand that I can forget to do something

What's the convention for using an asterisk at the end of a function name in Clojure and other Lisp dialects?

拜拜、爱过 提交于 2019-12-20 09:15:11
问题 Note that I'm not talking about ear muffs in symbol names, an issue that is discussed at Conventions, Style, and Usage for Clojure Constants? and How is the `*var-name*` naming-convention used in clojure?. I'm talking strictly about instances where there is some function named foo that then calls a function foo*. 回答1: In Clojure it basically means "foo* is like foo, but somehow different, and you probably want foo". In other words, it means that the author of that code couldn't come up with a

Get correct indentation in Resharper for object and array initializers

馋奶兔 提交于 2019-12-20 09:09:56
问题 Right now resharper formats our code like this: private readonly List<Folder> folders = new List<Folder> { new Folder() }; but I want it to look like this: private readonly List<Folder> folders = new List<Folder> { new Folder() }; I've been messing with the options a lot, but can't seem to get them right. Can you help? 回答1: I had the same issue with anonymous delegates. The fix for anonymous delegate formatting is here: I did finally find the way to fix this. The options for formatting