coding-style

How to generate Styled text for TextView while assembling string?

倾然丶 夕夏残阳落幕 提交于 2019-12-23 16:40:13
问题 I have a TextView that will hold a styled, multiline string. This text is generated line by line as the data is drawn from different sources bit by bit. As I grab each field, I add a Bold header to the TextView on a new line, then I add the data for that field in italics on a new line. Example formatting: Due Date July 22, 2010 Course CSC 350 I could set the styling like this: Spannable str = (Spannable) textview.getText(); str.setSpan(new StyleSpan(android.graphics.Typeface.Bold), 0, 8,

How wide should VB code get?

血红的双手。 提交于 2019-12-23 16:07:20
问题 In times past, most people coded on a terminal that was 80 characters wide. In many languages this has become, if not holy then close to it. But now many people have 20"+ monitors (or dual monitors), so screen real estate isn't as prime as it once was. So my question is this: in Visual Basic code, should code be limited to 80 characters, should there be no limit, or is it really a subjective thing, dependent on where you work and your own preferences? 回答1: I think it is subjective, but not

Ratio of real code to supporting code

≯℡__Kan透↙ 提交于 2019-12-23 15:28:11
问题 I'm finding only about 30% of my code actually solves problems, the rest is taken up by logging, tests, parameter checking, exceptions, error handling and so on. Do you find that in your code, and is there an IDE/Editor that allows you to hide code that's not interesting? OTOH are there languages which make the support code more manageable and smaller in size? Edit - I think we're all aware of the difference between business logic and other code. I'm not saying that the logging etc is not

Styles of main functions in C [duplicate]

北城以北 提交于 2019-12-23 13:06:10
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: What is the proper declaration of main? I am working on my C skills and I have noticed that int main( int argc, char *argv[] ) and return (EXIT_SUCCESS) instead of int main() and return 0 Why is this? 回答1: If you are going to ignore the argument list, it is reasonable and sensible to use: int main(void) { ... } The standards bless this usage, as well as the one with arguments. You get a warning from GCC if you

C++ library: .hpp + .inl (separate definitions and declarations) vs .hpp only (in-class body code)

偶尔善良 提交于 2019-12-23 12:19:19
问题 I'm rewriting my Windows C++ Native Library (an ongoing effort since 2002) with public release in mind. For the past 10 years I've been the sole beneficiary of those 150+ KLOC and I feel others might find good uses for it also. Currently the entire library is quite-templated and header only. That means all code is in the body of the classes. It's not very easy to manage but it's OK. I'm VERY tempted, after reading several C++ library coding guidelines, to break it into .hpp + .inl files.

android change style dynamically

二次信任 提交于 2019-12-23 12:15:57
问题 I've describef properties of my objects (nevermind what the object is) in styles.xml. I would like to change these properties dynamically in styles.xml. Does anybody know how can I do that? 回答1: I am seeing contradicting answers to this question. This says yes, but this says no. I looked at the android docs for the View and can not find any setStyle method. 回答2: You can do that like: In Activity: this.setTheme(R.style.ThemeRed); In styles.xml: <resources> <style name="ThemeBlack" parent="

What is the dominant style for parenthesization of Ruby function calls?

放肆的年华 提交于 2019-12-23 11:15:12
问题 Say I have func_a and func_b which both take one argument, and I want to pass the result of func_b to func_a . What is the most common way to parenthesize this? func_a func_b input func_a func_b(input) func_a(func_b input) func_a(func_b(input)) 回答1: You'd have to scan source to find the "most common". I try to write what makes sense under the circumstances, but would almost always use either: func_a func_b(arg) func_a(func_b(arg)) If the functions are named things that "sound like" a sentence

Which of `if x:` or `if x != 0:` is preferred in Python?

偶尔善良 提交于 2019-12-23 10:05:49
问题 Assuming that x is an integer, the construct if x: is functionally the same as if x != 0: in Python. Some languages' style guides explicitly forbid against the former -- for example, ActionScript/Flex's style guide states that you should never implicitly cast an int to bool for this sort of thing. Does Python have a preference? A link to a PEP or other authoritative source would be best. 回答1: The construct: if x: is generally used to check against boolean values. For int s the use of the

which is better, using a nullable or a boolean return+out parameter

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 09:32:12
问题 Lets say I have a function that needs to return some integer value. but it can also fail, and I need to know when it does. Which is the better way? public int? DoSomethingWonderful() or public bool DoSomethingWonderful(out int parameter) this is probably more of a style question, but I'm still curious which option people would take. Edit: clarification, this code talks to a black box (lets call it a cloud. no, a black box. no, wait. cloud. yes). I dont care why it failed. I would just need to

Is it possible to break code-behind into multiple partial files?

自作多情 提交于 2019-12-23 09:12:56
问题 I have a .aspx Web Form with a .aspx.cs code-behind. The code-behind is nearly 2000 lines long, and it's getting to the point where the only way to easily navigate it is to put a ton of spaces in between the sections, zoom out so I can see the physical look of the code, and then zoom in where I want to edit. In other words, it's a major pain. I'd like to split this 2000 line into different files that represent concepts in the code. So when I need to go edit some functionality in the "Employee