coding-style

C++ getters and setters best style

荒凉一梦 提交于 2019-12-03 21:07:19
in Java code convention is simple and obvious, in this style: public: int GetMyAge(){ return myAge; } void SetMyAge(int myAge){ this->myAge = myAge; } private: int myAge; (I know it's "again the same thing", but ) I have read most of related questions on SO and I still don't know "the best one" and "the most official" way to do it in C++. It can't be just a matter of preferences, can it ? EDIT: Seems like it can . The best style is the one that allows you and your team to make quality software that your clients continue to pay you for. How does this style work for you and your team? Do you

Indenting lambdas and nested actions

跟風遠走 提交于 2019-12-03 20:58:08
问题 When using lambdas, usually on TPL, I get lost on indentation... Are there some best practices to format this? For example, take this code: Task t1 = factory.StartNew(() => { DoSomething(); } .ContinueWith((t2) => { DoSomethingWhenComplete(); }, TaskContinuationOptions.OnlyOnRanToCompletion) ).ContinueWith((t3) => { DoSomethingOnError(); }, TaskContinuationOptions.OnlyOnFaulted); Is my "indentation" correct? In that example, I want to execute t1, then if it finished OK, execute t2, and on

What are the characteristics of spaghetti code?

假装没事ソ 提交于 2019-12-03 19:26:37
问题 Somebody said that when your PHP code and application use global variables then it must be spaghetti code (I assume this). I use WordPress a lot. As far as I know, it's the best thing near great PHP software. And it uses many global variables to interact between its components. But forget about that, because frankly, that's the only thing I know. So it's completely biased ;D So, I am just curious, What is the characteristic of spaghetti code? PS: the only thing I know is WordPress. So,

Ruby Memory Management

梦想与她 提交于 2019-12-03 18:30:12
问题 I have been using Ruby for a while now and I find, for bigger projects, it can take up a fair amount of memory. What are some best practices for reducing memory usage in Ruby? Please, let each answer have one "best practice" and let the community vote it up. 回答1: Don't do this: def method(x) x.split( doesn't matter what the args are ) end or this: def method(x) x.gsub( doesn't matter what the args are ) end Both will permanently leak memory in ruby 1.8.5 and 1.8.6. (not sure about 1.8.7 as I

Should commit messages be written in present or past tense? [closed]

天涯浪子 提交于 2019-12-03 18:24:26
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago . So which is it that you think is better and more intuitive? Fixed the XXX bug in YYY Fix the XXX bug in YYY Fixes the XXX bug in YYY Fixing the XXX bug in YYY Please provide your rationales. Note I am asking from your general perspective, meaning you should not try to

Default int type: Signed or Unsigned?

丶灬走出姿态 提交于 2019-12-03 17:57:47
问题 When programming in a C-like language should one's "default" integer type be int or uint/unsigned int? By default, I mean when you don't need negative numbers but either one should be easily big enough for the data you're holding. I can think of good arguments for both: signed: Better-behaved mathematically, less possibility of weird behavior if you try to go below zero in some boundary case you didn't think of, generally avoids odd corner cases better. unsigned: Provides a little extra

Most crucial elements in a light-weight C++ coding standard [closed]

荒凉一梦 提交于 2019-12-03 17:57:35
问题 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 7 years ago . I've been involved in developing coding standards which were quite elaborate. My own experience is that it was hard to enforce if you

Nested method calls vs. one-shot variables

爱⌒轻易说出口 提交于 2019-12-03 17:19:45
What is the best practice when nesting method calls or using one-shot variables? Should you never use one-shot variables? example: [persistentStoreCoordinator addPersistentStoreWithType:NSXMLStoreType configuration:nil URL:[NSURL fileURLWithPath: [applicationSupportDirectory stringByAppendingPathComponent: @"storedata"]] options:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:NSMigratePersistentStoresAutomaticallyOption] error:&error]; Should you always break up a nested method into one-shot variables? example: NSNumber *yesNumber = [NSNumber numberWithBool:YES];

How to make the cleanest code when reporting progress to a user?

这一生的挚爱 提交于 2019-12-03 17:11:12
问题 I've struggled for the last couple of months to come up with some clean code to report progress to a user. Everything always seems to boil down to: ReportProgress("Starting Task 1"); doTask1(); ReportProgress("Task 1 is done"); ReportProgress("Starting Task 2"); doTask2(); ReportProgress("Task 2 is done"); //etc... where report progress does some form of output to the user. The good coder in me screams "There's got to be a cleaner way!" But I'm stumped. Any thoughts? EDIT :: I'm looking more

Java coding convention about static method

戏子无情 提交于 2019-12-03 16:58:38
问题 It is a very simple question, but I think it is a little bit controversial. When I code Java classes I use the following order. class Foo { // static fields // instance fields // constructors // methods (non-static and static methods are mixed but sorted based on their functionalities) } I read an article that says: (From http://code.google.com/webtoolkit/makinggwtbetter.html#codestyle) Java types should have the following member order: Nested Types (mixing inner and static classes is okay)