coding-style

Am I immoral for using a variable name that differs from its type only by case?

霸气de小男生 提交于 2019-12-04 14:54:13
问题 For instance, take this piece of code: var person = new Person(); or for you Pythonistas: person = Person() I'm told constantly how bad this is, but have yet to see an example of the immorality of these two lines of code. To me, person is a Person and trying to give it another name is a waste of time. I suppose in the days before syntax highlighting, this would have been a big deal. But these days, it's pretty easy to tell a type name apart from a variable name. Heck, it's even easy to see

Change the content of a <style> element through JavaScript

倾然丶 夕夏残阳落幕 提交于 2019-12-04 13:04:36
问题 The Problem I have the following code: <html> <head> <style id="ID_Style"> .myStyle { color : #FF0000 ; } </style> </head> <body> <p class="myStyle"> Hello World ! </p> </body> </html> And I want to modify the contents of <style> through JavaScript. The Expected Solution The first solution was to use the innerHTML property of the style element (retrieved through its id), but while it works on Firefox, it fails on Internet Explorer 7. So, I used pure DOM methods, that is, creating an element

inline and good practices [duplicate]

十年热恋 提交于 2019-12-04 12:07:08
Possible Duplicate: When to use inline function and when not to use it ? I have seen many source codes using different syntaxes regarding the inline directive. namespace Foo { class Bar { public: // 1 - inline on the declaration + implementation inline int sum1(int a, int b) { return a + b; } // 2 - inline on template declaration + implementation template <typename T> inline T sum2(T a, T b) { return a + b; } // 3 - Nothing special on the declaration... int sum3(int a, int b); }; // 3 - But the inline directive goes after // In the same namespace and still in the header file inline int Bar:

Initializing map and set class member variables to empty in C++?

此生再无相见时 提交于 2019-12-04 11:43:31
问题 I have a C++ class with two member variables std::map<int, Node*> a; and std::set<Node*> b; A style checker used at my University requires all member variables to be initialized in the constructor of the class. How can these member variables a and b be initialized to empty in the constructor of the class they are in? 回答1: Like this: class A { public : A() : s(), m() { } std::set< int > s; std::map< int, double > m; }; 回答2: Like this SomeClass::SomeClass() : a(), b() {} ? 回答3: As both std::set

Interface / Abstract Class Coding Standard

末鹿安然 提交于 2019-12-04 11:28:30
问题 I spotted a proposed C# coding-standard which stated "Try to offer an interface with all abstract classes". Does someone know the rationale for this? 回答1: The .NET Framework Design Guidelines have some interesting things to say about interfaces and abstract classes. In particular, they note that interfaces have the major drawback of being less flexible than classes when it comes to the evolution of an API. Once you ship an interface, its members are fixed forever, and any additions will break

Is asserting that every object creation succeeded necessary in Objective C?

橙三吉。 提交于 2019-12-04 10:53:10
I have recently read Apple's sample code for MVCNetworking written by Apple's Developer Technical Support guru Quinn "The Eskimo!". The sample is really nice learning experience with what I guess are best development practices for iOS development. What surprised me, coming from JVM languages, are extremely frequent assertions like this: syncDate = [NSDate date]; assert(syncDate != nil); and this: photosToRemove = [NSMutableSet setWithArray:knownPhotos]; assert(photosToRemove != nil); and this: photoIDToKnownPhotos = [NSMutableDictionary dictionary]; assert(photoIDToKnownPhotos != nil); Is that

C error handling coding-style [closed]

南笙酒味 提交于 2019-12-04 10:49:28
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . In the case of the following code structure: int function_sequence(...) { f1(...); f2(...); f3(...); f4(...); f5(...); return SUCCESS; } Which way of the error handling is more acceptable? This: int function_sequence(...) { if(f1(...)){

Java naming convention with acronyms [duplicate]

不打扰是莪最后的温柔 提交于 2019-12-04 10:30:33
This question already has answers here : Closed 8 years ago . Possible Duplicate: Java Naming Convention with Acronyms Is it getXml() or getXML()? Is there any official Sun/Oracle document on this? Both are correct. Use your preferred way, and be consistent with it throughout your code. You'll find both in the Java Standard API, so if there is a convention, it's not being widely followed. Not specified Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter. Internal words start with capital letters. Variable names should not start with

How to integrate rubocop with Rake?

心不动则不痛 提交于 2019-12-04 09:55:51
问题 rubocop is a code style checker for Ruby. A similar tool to rubocop, Cane, can be integrated with Rake. I prefer rubocop to Cane since rubocop makes checks based on the Ruby Style Guide and it seems to spot more problems. To automate the process of style checking I would like to integrate rubocop with Rake so that the build fails if code quality is lacking. Gem already supports adding tests to packages via Rake. I would like to do the same with style checks so that style checks are run along

How to avoid duplicating logic on two similar WinForms?

纵饮孤独 提交于 2019-12-04 09:45:56
I have two forms, form A and form B. These forms must differ in appearance, but they share a lot of logic. The problem is that this logic is tied to the appearance (validation on button click, events being fired, etc.). For example, I have a name field, and when the save button is pressed, I need to fire an event which causes the parent form to validate the record name to avoid duplicates. Both forms need this logic, but their save buttons are in different places, and the tooltip that is shown when an error occurs also needs to appear in a different place. This is just one example, but does