coding-style

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

一个人想着一个人 提交于 2019-12-06 05:39:57
问题 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

inline and good practices [duplicate]

本秂侑毒 提交于 2019-12-06 04:25:51
问题 This question already has answers here : Closed 8 years ago . 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

C error handling coding-style [closed]

£可爱£侵袭症+ 提交于 2019-12-06 04:04:40
问题 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;

How important is it to indicate if a class implements an interface in Perl?

社会主义新天地 提交于 2019-12-06 03:53:51
问题 I've been discussing a code style issue with a friend. We have a series of packages that implement an interface by returning a specific type of value via a named subroutine. For example: package Foo::Type::Bar; sub generate_foo { # about 5-100 lines of code return stuff here; } So you can go: my $bar_foo = Foo::Type::Bar->generate_foo; my $baz_foo = Foo::Type::Baz->generate_foo; We have many of these, all under the same Foo::Type::* hierarchy. I think the packages should clearly indicate that

Stylistic question concerning returning void

爷,独闯天下 提交于 2019-12-06 03:05:18
问题 Consider the following contrived example: void HandleThat() { ... } void HandleThis() { if (That) return HandleThat(); ... } This code works just fine, and I'm fairly sure it's spec-valid, but I (perhaps on my own) consider this unusual style, since the call appears to return the result of the function, despite the fact that both functions are prototyped to be void. Typically, I would expect to see: if (That) {HandleThat(); return;} which, I feel, leaves no ambiguity as to what's going on. SO

Fast input output function

此生再无相见时 提交于 2019-12-06 02:45:33
问题 #define getcx getchar_unlocked inline void inp( int &n )//fast input function { n=0; int ch=getcx();int sign=1; while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getcx();} while( ch >= '0' && ch <= '9' ) n = (n<<3)+(n<<1) + ch-'0', ch=getcx(); n=n*sign; } Hi I have been using the above function for input in various coding contests but was never able to understand why is it fast. I know the logic but don't know the concept of it's fastness. For example what is this line doing "#define getcx

shorthand typedef pointer to a constant struct

▼魔方 西西 提交于 2019-12-06 02:30:35
Declaring a struct with typedef typedef struct some_struct { int someValue; } *pSomeStruct; and then passing it as a parameter to some function with const declaration, implying 'const some_struct * var' void someFunction1( const pSomeStruct var ) turns out to become some_struct * const var This is also stated in Section 6.7.5.1 of the ISO C standard which states that 'const' in this case applies to the pointer and not to the data to which it points. So the question is - is there a way to declare a pointer to a const struct in a shorthanded notation with typedef, or there must always be a

When does it make sense to typedef basic data types?

余生颓废 提交于 2019-12-06 02:05:27
问题 A company's internal c++ coding standards document states that even for basic data types like int, char, etc. one should define own typedefs like "typedef int Int". This is justified by advantage of portability of the code. However are there general considerations/ advice about when (in means for which types of projects) does it really make sense? Thanks in advance.. 回答1: Typedefing int to Int offers almost no advantage at all (it provides no semantic benefit, and leads to absurdities like

Create custom VisualState in xaml and manually set it in CodeBehind

和自甴很熟 提交于 2019-12-06 01:50:02
问题 I have a TabItem style, which has VisualStates. <VisualState x:Name="MouseOver"> <!-- Tab turns bronze when mouseover --> </VisualState> Now I want to have a custom visual state and manually set the state in codebehind instead of relying on the MouseOver event. <VisualState x:Name="CustomVisualState"> <!-- this will be a storyboard to cause flashing --> </VisualState> Then I need to set it in CodeBehind. MyTabItem.VisualState = CustomVisualState. //something like this 回答1: Have you tried

Bash convention for if ; then

荒凉一梦 提交于 2019-12-06 01:38:54
问题 From this web page : http://tldp.org/LDP/abs/html/abs-guide.html It's mentioned the usage of the if bracket then convention which need a space after the semicolon : ; Command separator [semicolon]. Permits putting two or more commands on the same line. echo hello; echo there if [ -x "$filename" ]; then # Note the space after the semicolon. #+ ^^ echo "File $filename exists."; cp $filename $filename.bak else # ^^ echo "File $filename not found."; touch $filename fi; echo "File test complete."