coding-style

Ensure coding-style during a git commit [closed]

风流意气都作罢 提交于 2020-01-01 05:29:05
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . Im my company i set-up a continuous integration test and i run the tests when someone push the code on the server. Now i want to check that the code match with the our basic coding rules, the first rule is "run mogrify on your code!" There is something to do this check "out the shelf"? the output of this analisys

Why use infinite loops?

最后都变了- 提交于 2020-01-01 05:00:06
问题 Another poster asked about preferred syntax for infinite loops. A follow-up question: Why do you use infinite loops in your code? I typically see a construct like this: for (;;) { int scoped_variable = getSomeValue(); if (scoped_variable == some_value) { break; } } Which lets you get around not being able to see the value of scoped_variable in the for or while clause. What are some other uses for "infinite" loops? 回答1: A loop like: while (true) { // do something if (something else) break; //

Call member function on each element in a container

独自空忆成欢 提交于 2020-01-01 04:54:06
问题 This question is a matter of style, since you can always write a for loop or something similar; however, is there a less obtrusive STL or BOOST equivalent to writing: for (container<type>::iterator iter = cointainer.begin(); iter != cointainer.end(); iter++) iter->func(); ? Something like (imagined) this: call_for_each(container.begin(), container.end(), &Type::func); I think it would be 1) less typing, 2) easier to read, 3) less changes if you decided to change base type/container type. EDIT

Modifying the innerHTML of a <style> element in IE8

断了今生、忘了曾经 提交于 2020-01-01 04:12:05
问题 I am creating a style element and I need to put some CSS into it. The below code works in Chrome, Safari and FF, but fails in IE8: var styleElement = document.createElement("style"); styleElement.type = "text/css"; styleElement.innerHTML = "body{background:red}"; document.head.appendChild(styleElement); In IE8, the code fails when it comes to the innerHTML part. I've tried doing: var inner = document.createTextNode("body{background:red}"); styleElement.appendChild(inner); But this also fails

“if” considered harmful in ASP.NET MVC View (.aspx) files?

会有一股神秘感。 提交于 2020-01-01 03:22:07
问题 I remember seeing a blog (or something) that said you should not use <% if ... %> in .aspx files in ASP.NET MVC, but I can't remember what it said the alternative is. Can anyone remember seeing this and point me to it? 回答1: I'm not sure if this is what you saw, but here is a blog that mentions it. See item #11. 回答2: Basically what it means is that you shouldn't have huge if statements in your Views, your Controllers and ViewModels should be able to handle the logic. Example: <h2 class="title"

Why is it customary to put many closing parentheses on one line in Lisp-based languages?

霸气de小男生 提交于 2020-01-01 01:30:08
问题 Usually code looks like this: (one-thing (another-thing arg1 (f arg5 r)) (another-thing arg1 (f arg5 r))) Why doesn't it like this?: (one-thing (another-thing arg1 (f arg5 r)) (another-thing arg1 (f arg5 r)) ) It allows adding and removing "another-thing" lines more easily (without removing and re-adding trailing closing parenthesis). Also you can put a some comment on that lone closing parenthesis (such as "; end of the loop"). How bad is it when I mix by code that uses the second style with

is there a pragmatic reason to use “if (0 == p) ” instead of “if (!p)”?

对着背影说爱祢 提交于 2019-12-31 20:37:52
问题 I'm inclined to write if statements by using logical negation operator: if (!p) some_code(); Some people around me tend to use explicit comparison, so that the code looks like: if (FOO == p) some_code(); where FOO is one of false , FALSE , 0 , 0.0 , NULL , etc. I prefer the short form because it is: operator!= friendly generic programming friendly laconic (and even more beautiful , as for me) What are the pragmatic benefits of writing this otherwise (if any)? 回答1: Some claim that the

How to justify to your colleagues that they produce crappy code?

自作多情 提交于 2019-12-31 12:16:13
问题 I am finding somewhat difficult to carry on working in my current job. The codebase has become a bit wild lately (but definitely not the worse I've seen), and I'm having a hard time dealing with some parts of the code. I could be stupid, but most likely it's just that it demotivates me a lot to start working on something that is hard to reason about. My boss is already aware of my thoughts - I expressed what it feels like to work like this. He asked me to provide examples of what was wrong.

How do I set the default linestyle for plots in MATLAB?

爷,独闯天下 提交于 2019-12-31 10:00:47
问题 I have an array of data that I would like to plot temp=0.5*rand(500,10); [~,offset]=meshgrid(1:500,1:10); figure(101) plot(temp+offset') How can I set the line style to automatically change to the next style once the line colours have been through one cycle? For this example I would like the 8-10th lines to have a different line style. I can do it manually but I'd like Matlab to do it for me if I can set a default option somewhere. 回答1: Your first inclination might be to just change the

In Intellij, how do I toggle between camel case and underscore spaced?

此生再无相见时 提交于 2019-12-31 07:53:27
问题 At my company we have two different style guides for java vs sql. In java I have a field named historyOfPresentIllness and when i write the sql, I want to name it history_of_present_illness . Is there a keyboard shortcut to switch from one to the other when I have the phrase highlighted? Or perhaps a plugin that can do this? While I'm asking, I may as well ask if there's a way to turn historyOfPresentIllness to history-of-present-illness . That's from java to clojure style. 回答1: I use a