coding-style

How to create an Intellij and Eclipse compatible code style and code formatting configuration (for java code)?

你说的曾经没有我的故事 提交于 2019-12-17 18:26:17
问题 Few weeks ago I tried Intellij and I found it really awesome. Now, at my project there are two programmers (including me) using Intellij and few other programmers who are going to keep using Eclipse. Since this project is already very large and it's going to grow a lot, we need to use compatible Code Style and Code Formatting between Intellij and Eclipse. We do not want to have problems when one user edits some file and reformats it before saving. With Eclipse "alone" we used to have some

Factory method for objects - best practice?

我的梦境 提交于 2019-12-17 18:05:10
问题 This is a question regarding the best practice for creating an instance of a class or type from different forms of the same data using python. Is it better to use a class method or is it better to use a separate function altogether? Let's say I have a class used to describe the size of a document. (Note: This is simply an example. I want to know the best way to create an instance of the class not the best way to describe the size of a document.) class Size(object): """ Utility object used to

instance variable/ method argument naming in Objective C

*爱你&永不变心* 提交于 2019-12-17 17:57:10
问题 What conventions are people here following for naming of instance variables and method arguments - particularly when method arguments are used to set ivars (instance variables)? In C++ I used to use the m_ prefix for ivars a lot. In C# I followed the convention of disambiguating purely by use of this. for ivars. I've since adopted the equivalent in C++ too ( this-> ). In Objective C I've tried a few things but none have really seemed satisfactory. Unless someone suggests something really nice

Catching specific vs. generic exceptions in c#

大城市里の小女人 提交于 2019-12-17 17:52:50
问题 This question comes from a code analysis run against an object I've created. The analysis says that I should catch a more specific exception type than just the basic Exception. Do you find yourself using just catching the generic Exception or attempting to catch a specific Exception and defaulting to a generic Exception using multiple catch blocks? One of the code chunks in question is below: internal static bool ClearFlags(string connectionString, Guid ID) { bool returnValue = false;

How to concisely cascade through multiple regex statements in Python

柔情痞子 提交于 2019-12-17 17:48:14
问题 My dilemma: I'm passing my function a string that I need to then perform numerous regex manipulations on. The logic is if there's a match in the first regex, do one thing. If no match, check for a match with the second and do something else, if not check the third, and so forth. I could do something like this: if re.match('regex1', string): match = re.match('regex1', string) # Manipulate match.group(n) and return elif re.match('regex2', string): match = re.match('regex2', string) # Do second

Should I use Single() or SingleOrDefault() if there is a chance that the element won't be found?

孤人 提交于 2019-12-17 17:39:48
问题 What would you prefer to see? try { var item = list.Single(x => x.HasFoo); } catch(InvalidOperationException e) { throw new InvalidOperationException("Exactly one item with foo expected, none found", e); } Or: var item = list.SingleOrDefault(x => x.HasFoo); if (item == null) throw new InvalidOperationException("Exactly one item with foo expected, none found"); What's the best practice here? Which one makes the exception more comprehensible? 回答1: Use SingleOrDefault() if 0 or 1 items are

What are the naming guidelines for ASP.NET controls?

我们两清 提交于 2019-12-17 17:34:31
问题 We are in the process of nutting out the design guidelines we would like to use in our development team and got into a discussion today around how ASP.NET controls should be named. I am talking about our good friends Label, TextBox, Button etc. We came up with the following three possibilities that we voted on: (Example is a TextBox to enter/display a FirstName) Add the control type as a postfix to your controls ID: [FirstName _ TextBox] or [FirstName _ tbx] Add the control type as a prefix

Java/Swing GUI best practices (from a code standpoint) [closed]

给你一囗甜甜゛ 提交于 2019-12-17 17:29:01
问题 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 8 years ago . As a contrast to this wiki, I am looking for the proper way to implement Swing GUI controls from a coding standpoint. I have been on a quest to learn Java and its GUI tools but I find internet tutorial after internet tutorial that throws everything in main and I know this isn't right. I've also tried RAD systems

Internal typedefs in C++ - good style or bad style?

别等时光非礼了梦想. 提交于 2019-12-17 17:19:03
问题 Something I have found myself doing often lately is declaring typedefs relevant to a particular class inside that class, i.e. class Lorem { typedef boost::shared_ptr<Lorem> ptr; typedef std::vector<Lorem::ptr> vector; // // ... // }; These types are then used elsewhere in the code: Lorem::vector lorems; Lorem::ptr lorem( new Lorem() ); lorems.push_back( lorem ); Reasons I like it: It reduces the noise introduced by the class templates, std::vector<Lorem> becomes Lorem::vector , etc. It serves

OO Design - do you use public properties or private fields internally? [duplicate]

北战南征 提交于 2019-12-17 16:58:10
问题 This question already has answers here : What is the best way to access properties from the same class, via accessors or directly? [closed] (5 answers) Closed 6 years ago . I'm working in C# 2.0, but this would apply to most object oriented languages. When I create classes with public properties that wrap private fields, I switch back & forth between whether I should use the property or field internally. Of course C# 3.0 makes this easier with auto-properties, but it could still apply. Does