coding-style

Git: Run through a filter before commiting/pushing?

穿精又带淫゛_ 提交于 2019-12-19 09:49:33
问题 Is there a way to run the changed files through a filter before doing the commit? I wish to make sure the files follows the coding standards for the project. I would also like to compile and run some test before the commit/push actually takes place, so I know everything in the repo actually works. 回答1: Pre-commit hooks. Read up on git hooks. The Git Book has an example of how to write a Ruby script to run RSpec tests, for instance. You just save the executable as .git/hooks/pre-commit - using

Are DefType statments considered Bad Practice?

梦想的初衷 提交于 2019-12-19 08:55:15
问题 I want your thoughts on why or (why not) this statement should (or should not) be used. Since this is a little subjective, here is my criteria: Upvotes given for concrete reasons (as opposed to unreasoned opinion). Final answer accepted will be the most comprehensive answer. 回答1: In a well-crafted program, Defxxx statements are pointless, because all variables and functions will be explicitly typed. Except for one case: DefObj A-Z, in conjunction with Option Explicit, makes it (practically)

Should I use string constants or string literals

好久不见. 提交于 2019-12-19 08:29:25
问题 By default I use string constants in my code when I have a string of text that will be output to the screen via a messagebox, label, etc. My main reason for doing so is that I do not want these strings to change at runtime and this way nobody really touches them. My question is: It seems that from a memory point of view, this approach is creating an object whose lifetime will be decided by the GB whereas a string literal seems more efficient and will be disposed of more quickly. I know this

When to use an elaborated type specifier

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-19 05:59:56
问题 Is there a particularly good reason to choose to use an elaborated type specifier? For example, in certain circumstances, one is required to use the template or typename keywords to disambiguate a dependent template or type. But I can't think of any examples where this would occur for something such as an enumeration. Take the following code example: enum Foo { A, B }; void bar(Foo foo); void baz(enum Foo foo); Why might I choose to use the syntax baz() provides over bar() (or vice-versa)? Is

When to use an elaborated type specifier

五迷三道 提交于 2019-12-19 05:59:07
问题 Is there a particularly good reason to choose to use an elaborated type specifier? For example, in certain circumstances, one is required to use the template or typename keywords to disambiguate a dependent template or type. But I can't think of any examples where this would occur for something such as an enumeration. Take the following code example: enum Foo { A, B }; void bar(Foo foo); void baz(enum Foo foo); Why might I choose to use the syntax baz() provides over bar() (or vice-versa)? Is

Multiple DbContext classes for a single web app. Good or bad?

大兔子大兔子 提交于 2019-12-19 05:52:48
问题 Is it a good practice to have multiple XXX : DbContext classes for each major section of a web application (considering it's a big one with at least 50 tables in its database)? For example: MembershipContext, BlogContext, StoreContext etc. Or it's more convenient to have a single DatabaseContext for all the db access related stuff. 回答1: Using multiple DbContext classes implies complicating cross-transactions (you can find a solution to this problem on the web here an example http://pastebin

Findbugs issues with mutability of Date object in Java

若如初见. 提交于 2019-12-19 05:20:39
问题 This is more of a follow-up to questions 1 & 2. As told in the questions the below code public Date getSomeDate() { return someDate; } will give you the findbug error issue. The suggested solution was to duplicate the Date object in both getters and setters like public Date getSomeDate() { return new Date(someDate.getTime()); } Is this a good approach or are there any alternative ways to this? Is there any Immutable Date library available in java that can overcome this issue? 回答1: JodaTime

Is using “base” bad practice even though it might be good for readability?

穿精又带淫゛_ 提交于 2019-12-19 05:19:28
问题 I know this is a subjective question, but I'm always curious about best-practices in coding style. ReSharper 4.5 is giving me a warning for the keyword "base" before base method calls in implementation classes, i.e., base.DoCommonBaseBehaviorThing(); While I appreciate the "less is better" mentality, I also have spent a lot of time debugging/maintaining highly-chained applications, and feel like it might help to know that a member call is to a base object just by looking at it. It's simple

Idiomatic Python logging: format string + args list vs. inline string formatting - which is preferred?

北城以北 提交于 2019-12-19 05:13:23
问题 Is it advantageous to call logging functions with format string + args list vs. formatting inline? I've seen (and written) logging code that uses inline string formatting: logging.warn("%s %s %s" % (arg1, arg2, arg3)) and yet I assume it's better (performance-wise, and more idiomatic) to use: logging.warn("%s %s %s", arg1, arg2, arg3) because the second form avoids string formatting operations prior to invoking the logging function. If the current logging level would filter out the log

Is it wrong to use braces for variable scope purposes?

允我心安 提交于 2019-12-19 05:08:05
问题 I sometimes use braces to isolate a block of code to avoid using by mistake a variable later. For example, when I put several SqlCommand s in the same method, I frequently copy-paste blocks of code, ending by mixing the names and executing twice some commands. Adding braces helps to avoid this situation, because using a wrong SqlCommand in a wrong place will result in an error. Here's an illustration: Collection<string> existingCategories = new Collection<string>(); // Here a beginning of a