coding-style

What's the best way to layout a C# class? [duplicate]

做~自己de王妃 提交于 2019-12-18 09:59:23
问题 This question already has answers here : Order of items in classes: Fields, Properties, Constructors, Methods (15 answers) Closed 6 years ago . Is there a standard way of laying out a C# file? As in, Fields, then Properties, then Constructors, etc? Here's what I normally do, but I'm wondering if there's a standard way? Nested Classes or Enums Fields Properties Events Constructors Public Methods Private Methods Do people group their fields together, or do they put them with the properties? Or

Checking in of “commented out” code [closed]

半世苍凉 提交于 2019-12-18 09:57:25
问题 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 . Ok, here is something that has caused some friction at my current job and I really didn't expect it to. Organized in house software development is a new concept here and I have drawn up a first draft of some coding guidelines. I have proposed that "commented out" code should

What's the difference between 'false === $var' and '$var === false'?

限于喜欢 提交于 2019-12-18 09:29:03
问题 Is one more readable than the other? At first, I disliked the false === approach but as I see it more and more often, I'm warming up to it. I'm pretty sure they return identical results. 回答1: I greatly prefer false === $var Namely because sometimes you are only using equality and not looking for identity. In which case you write false == $var But sometimes you aren't at the top of your game, and might write false = $var which will give an immediate error, and let's you fix it right away.

How to override virtual function in good style? [C++]

好久不见. 提交于 2019-12-18 07:44:28
问题 guys I know this question is very basic but I've met in few publications (websites, books) different style of override virtual function. What I mean is: if I have base class: class Base { public: virtual void f() = 0; }; in some publications I saw that to override this some authors would just say: void f(); and some would still repeat the virtual keyword before void. Which form of overwriting is in good style? Thank you for your answers. 回答1: This is purely a matter of taste. Some weak

How to override virtual function in good style? [C++]

守給你的承諾、 提交于 2019-12-18 07:44:25
问题 guys I know this question is very basic but I've met in few publications (websites, books) different style of override virtual function. What I mean is: if I have base class: class Base { public: virtual void f() = 0; }; in some publications I saw that to override this some authors would just say: void f(); and some would still repeat the virtual keyword before void. Which form of overwriting is in good style? Thank you for your answers. 回答1: This is purely a matter of taste. Some weak

Convention for pointer *

本秂侑毒 提交于 2019-12-18 06:31:30
问题 Out of curiosity; why is convention for pointers in C languages like this: NSString *str = ... Wouldn't be more appropriate to write: NSString* str = ... because we are defining pointer to NSString? (in Objective-C methods we do have (NSString*)parameter1 convention) Again - I'm asking out of curiosity and to be able to better understand logic behind this... I'm not trying to reinvent the wheel or start flame war. 回答1: If you declare multiple pointer variables in a single declaration, you

In Python, can you call an instance method of class A, but pass in an instance of class B?

只愿长相守 提交于 2019-12-18 05:59:30
问题 In the interest of reusing some existing code that was defined as an instance method of a different class, I was tying to do something like the following: class Foo(object): def __init__(self): self.name = "Foo" def hello(self): print "Hello, I am " + self.name + "." class Bar(object): def __init__(self): self.name = "Bar" bar = Bar() Foo.hello(bar) but that results in: TypeError: unbound method hello() must be called with Foo instance as first argument (got Bar instance instead) Is something

return (a) vs. return a

让人想犯罪 __ 提交于 2019-12-18 05:51:12
问题 I have seen both in the C and C++ code I have been looking at. What is the difference? 回答1: No difference at all. The official syntax is return something; or return; and of course it is a keyword, not a function. For this reason you should not read it as return( a ); but as return (a); I think the difference is subtle but clear, parentheses will not apply to return but to a. ((((a)))) is the same as (a) that is the same as a . You can also write something like... int x = (((100))); You can

Style datagrid table - Top left corner

帅比萌擦擦* 提交于 2019-12-18 05:04:39
问题 I am styling a datatable but I can't figure out how to style the top left filed of the datagrid. It is the gray field in this picture: Do you know how to do it? Here is my style so far: <Style TargetType="{x:Type DataGrid}"> <Setter Property="Margin" Value="5" /> <Setter Property="Background"> <Setter.Value> <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> <GradientStop Color="White"/> <GradientStop Color="AliceBlue" Offset="1"/> </LinearGradientBrush> </Setter.Value> </Setter>

Combining multiple attributes in C#

二次信任 提交于 2019-12-18 04:32:00
问题 Is there a functional difference between the following syntax... [Foo, Bar] public class Baz {} ...and this syntax? [Foo] [Bar] public class Baz {} Assuming each produces identical results when compiled, which is the preferred form? 回答1: There is no functional difference. It's a question of convenience and style. Most often, I tend to see attributes on their own lines as a way to keep them separate and easy to read. It's also nice to be able to use the line comment // to remove attributes