coding-style

Using @string resource inside a style definition

社会主义新天地 提交于 2019-12-10 16:16:33
问题 I have something like the following (shown below) defined in my styles.xml file. But Android crashes due to the use of the @string/fontExtraLarge. I'm assuming it's because of the order of definition, but is this legal. I could use the style 'parent' attribute to resolve this, but for only one style definition doesn't make sense. Is there a way to resolve this problem. BTW, the error I get is Unable to Inflate XML which points to the layout.XML, but really this file is causing this issue. <!-

What is the most common way of ordering Java methods?

旧街凉风 提交于 2019-12-10 16:16:06
问题 Ordering Java methods is probably the least important code style issue ever, but I'm trying to develop a code style as similar to what most people do as possible. It's by far the most popular approach to first declare all fields and then all methods, so I'll only ask about methods. Now I'm wondering how to order Java methods. I can think of two sensible basic approaches: Order methods by visibility (i.e. first public, then protected, then private or the other way around) Order methods by

Why is it preferable to write func( const Class &value )?

好久不见. 提交于 2019-12-10 15:56:31
问题 Why would one use func( const Class &value ) rather than just func( Class value ) ? Surely modern compilers will do the most efficient thing using either syntax. Is this still necessary or just a hold over from the days of non-optimizing compilers? Just to add, gcc will produce similar assembler code output for either syntax. Perhaps other compilers do not? Apparently, this is just not the case. I had the impression from some code long ago that gcc did this, but experimentation proves this

Should names representing template types be a single character?

耗尽温柔 提交于 2019-12-10 14:59:17
问题 we're defining some C++ coding style guidelines based on these guidelines. Number 8 says "Names representing template types should be a single uppercase letter." Explanation: "Common practice in the C++ development community. This makes template names stand out relative to all other names used." Is it really that common? I agree that it makes a lot of sense to have template<class T> class vector {...} . But what if I have several template Arguments? I don't think that <class A, class B> is

Is there any advantage on separating iPhone and iPad classes on a Universal app?

雨燕双飞 提交于 2019-12-10 14:12:11
问题 I have a Universal (for both iPhone and iPad) application. Are there any advantages on separating the iPad from the iPhone classes in the folder structure? Here is an example of what I mean: - MyApp - Resources - Classes - iPad - SomeUniqueClassOnIPad.h - SomeUniqueClassOnIPad.m - iPhone - SomeUniqueClassOnIPhone.h - SomeUniqueClassOnIPhone.m - SomeUniversalClass.h - SomeUniversalClass.m Is that common in objective-c projects? 回答1: One of the rules within coding is never to have duplicate

Departmental restriction against unsafePerformIO

别说谁变了你拦得住时间么 提交于 2019-12-10 14:12:06
问题 There has been some talk at work about making it a department-wide policy of prohibiting the use of unsafePerformIO and its ilk. Personally, I don't really mind as I've always maintained that if I found myself wanting to use it, it usually meant that I need to rethink my approach. Does this restriction sound reasonable? I seem to remember reading somewhere that it was included mainly for FFI, but I can't remember where I read that at the moment. edit: Ok, that's my fault. It wouldn't be

Should I log before or after an operation?

Deadly 提交于 2019-12-10 14:08:06
问题 I'm thinking about where to write the log record around an operation. Here are two different styles. The first one, write log before the operation. Before: log.info("Perform operation XXX") operation() And here is a different style, write the log after the operation. After: operation() log.info("Operation XXX is done.") With the before-style, the logging records say what is going to do now. The pro of this style is that when something goes wrong, developer can detect it easily, because they

What happens when there is partial initialization of an array of struct in C?

限于喜欢 提交于 2019-12-10 13:55:27
问题 What does this code mean? struct foo_t { int a; int b; } foo[10] = {{0,0}} foo[0] is {0,0} , but what about the rest? How does the C standard handle this? ADDED. I founded an exhaustive answer here. I think my question should be deleted. 回答1: The entire array will be initialized with structs with the value 0 for both a and b . This is similar to the following case with a primitive value: int foo[10] = {0}; Where every integer in the array will be initialized with the value 0 . The C99

Correct way to prevent instantiation in Java [closed]

穿精又带淫゛_ 提交于 2019-12-10 13:46:50
问题 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 . If we want to prevent instantiation of object in Java we can use several approaches and most obvious of them: abstract keyword private

Should I use EventArgs or a simple data type?

五迷三道 提交于 2019-12-10 13:35:54
问题 I'm currently creating a library for fun and practice and I was wondering, when raising an event, how to choose between passing your own EventArgs derivative or just the data type. For example, in my library I have something like this: public delegate void LostConnectionEventHandler(string address); public delegate void MessageReceieved(byte[] bytes); What is the standard practice for this? Should I replace string address with ConnectionEventArgs and byte[] bytes with MessageEventArgs ? I