code-readability

Readability vs Performance

北城余情 提交于 2019-12-04 16:25:38
问题 Recently we had a discussion at work about the impact of local variables on the performance vs readability of Java code. Some of my colleagues are of the oppinion that declarations like this new DoSomethingCmd(new SelectionContext(context, keys), infoStuff.getCurrentRole().getRole_id()).execute(getResultContainer()); will give the application a considerable performance boost. They are willing to sacrifice code readability for this. Are they right in claiming this? Is the above version

How do I align/format code in Android Studio?

十年热恋 提交于 2019-12-04 15:19:02
问题 Is there a way/shortcut/built-in feature that can align code for operands, like '=' signs? For example, there is a XAlign for Xcode (https://github.com/qfish/XAlign), allowing the user to select code that needs to be aligned and use a shortcut to align it automatically. There is a Fields Group feature in Android Studio which can "Align in columns", but it does not work for code that is already written. 回答1: Indent code in Android Studio: Windows Ctrl + Alt + L Mac: Option + Command + L 回答2:

Which is fast : Query Syntax vs. Loops

与世无争的帅哥 提交于 2019-12-04 09:08:32
The following code provides two approaches that generate pairs of integers whose sum is less than 100, and they're arranged in descending order based on their distance from (0,0). //approach 1 private static IEnumerable<Tuple<int,int>> ProduceIndices3() { var storage = new List<Tuple<int, int>>(); for (int x = 0; x < 100; x++) { for (int y = 0; y < 100; y++) { if (x + y < 100) storage.Add(Tuple.Create(x, y)); } } storage.Sort((p1,p2) => (p2.Item1 * p2.Item1 + p2.Item2 * p2.Item2).CompareTo( p1.Item1 * p1.Item1 + p1.Item2 * p1.Item2)); return storage; } //approach 2 private static IEnumerable

How Do I Avoid Line-Break Padding?

半世苍凉 提交于 2019-12-04 04:37:07
My biggest gripe with HTML is that line breaks add a tiny bit of space between elements. ( jsFiddle .) This can screw up layouts where child elements are sized to exactly fit their parents. I read somewhere that you can remove this implicit padding - while still keeping the code somewhat legible - by using comments like this: <!-- --><div>Foo</div><!-- --><div>Bar</div><!-- --><div>And so on...</div><!-- --> This works, but I feel like there has to be a better solution. What other ways are there to work around the line-break padding? That isn't "a little bit of space", but literally a space

From-Import while retaining access by module

隐身守侯 提交于 2019-12-04 04:27:20
问题 The title is a little hard to understand, but my question is simple. I have a program that needs to take the sqrt() of something, but that's the only thing I need from math . It seems a bit wasteful to import the entire module to grab a single function. I could say from math import sqrt , but then sqrt() would be added to my program's main namespace and I don't want that (especially since I plan to alter the program to be usable as a module; would importing like that cause problems in that

How to cleanly keep below 80-char width with long strings?

扶醉桌前 提交于 2019-12-04 02:47:02
问题 I'm attempting to keep my code to 80 chars or less nowadays as I think it looks more aesthetically pleasing, for the most part. Sometimes, though, the code ends up looking worse if I have to put line breaks in weird places. One thing I haven't figured out how to handle very nicely yet is long strings. For example: #0.........1........2........3........4.........5.........6.........7.........8xxxxxxxxx9xxxxxx def foo(): if conditional(): logger.info("<Conditional's meaning> happened, so we're

Readability vs Performance

风流意气都作罢 提交于 2019-12-03 10:32:35
Recently we had a discussion at work about the impact of local variables on the performance vs readability of Java code. Some of my colleagues are of the oppinion that declarations like this new DoSomethingCmd(new SelectionContext(context, keys), infoStuff.getCurrentRole().getRole_id()).execute(getResultContainer()); will give the application a considerable performance boost. They are willing to sacrifice code readability for this. Are they right in claiming this? Is the above version significantly more performant than, say, this one? final SelectionContext selectionContext = new

How do I align/format code in Android Studio?

北慕城南 提交于 2019-12-03 10:31:43
Is there a way/shortcut/built-in feature that can align code for operands, like '=' signs? For example, there is a XAlign for Xcode ( https://github.com/qfish/XAlign ), allowing the user to select code that needs to be aligned and use a shortcut to align it automatically. There is a Fields Group feature in Android Studio which can "Align in columns", but it does not work for code that is already written. Jorgesys Indent code in Android Studio: Windows Ctrl + Alt + L Mac: Option + Command + L Syed Atir Mohiuddin In Eclipse which comes with Android Studio Bundle, the shortcut key is as follows

How to deal with Pylint's “too-many-instance-attributes” message?

做~自己de王妃 提交于 2019-12-03 04:30:54
问题 I have just tried to lint some code with Pylint, and the last remaining error is R0902: too-many-instance-attributes (8/7) I understand the rationale behind limiting the number of instance attributes, but seven seems a bit low. I also realise that the linter should not have the last word. However, I would like to know what I should be doing instead of: def __init__(self, output_file=None, output_dir=None): """ Set the frobnicator up, along with default geometries """ self.margin = 30 self.pos

Studies on optimal code width?

笑着哭i 提交于 2019-12-03 00:08:56
问题 If you enable the "View Right Margin" in your IDE of choice, it is likely that it will default to 80 characters. I tend to change it to 120 for no reason other than it was the standard at a company I was with a few years back, and no other company has told me to do it differently. My question is, are there any studies that actually show 80 characters to be the optimal maximum width for code readability, or is this value just a "that's the way it's always been" and no one really knows why it