code-readability Questions
1
How can I save a file with the name as: oldname+"_new"+extension in an elegant way?
I currently do:
ext = os.path.splitext(file)[1]
output_file = (root+'/'+ os.path.splitext(file)[0]+&quo...
Baalman asked 15/4, 2024 at 9:35
4
Solved
I'm working on a program in Go, that makes heavy usage of MySQL. For sake of readability, is it possible to include the value of a column after each column name in an INSERT statement? Like:
INSER...
Resonant asked 22/9, 2013 at 2:18
11
Solved
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 c...
Malefaction asked 23/2, 2009 at 15:40
3
Solved
Now a days i switched to sonar reports for static code review and performance improvement. Under the rules section I found that the cognitive complexity of my methods are high.
You can find cognit...
Stroy asked 10/10, 2018 at 13:46
7
Solved
I have some topic to discuss. I have a fragment of code with 24 ifs/elifs. Operation is my own class that represents functionality similar to Enum. Here is a fragment of code:
if operation == Oper...
Wedge asked 31/7, 2015 at 14:27
6
Solved
I'm new-ish to JavaScript. I understand many of the concepts of the language, I've been reading up on the prototype inheritance model, and I'm whetting my whistle with more and more interactive fro...
Bantu asked 22/4, 2012 at 23:49
11
Solved
I have a question about idioms and readability, and there seems to be a clash of Python philosophies for this particular case:
I want to build dictionary A from dictionary B. If a specific key doe...
Liverwort asked 22/12, 2010 at 18:48
2
Solved
This is more of an open Question on how to deal with functions that have type altering side effects in TypeScript. I know and strongly agree with the notion, that functions should have as few side ...
Plaque asked 23/7, 2020 at 18:26
2
Solved
I am wondering, what the standard placement in a Python file for __all__?
My assumption is directly below the import statements. However, I could not find this explicitly stated/asked anywhere. So,...
Grith asked 8/1, 2020 at 2:21
3
Solved
Looking at GenericWhitespaceCheck in Checkstyle documentation,
Left angle bracket (<):
should be preceded with whitespace only in generic methods definitions.
should not be preceded with white...
Outrageous asked 27/12, 2019 at 17:17
4
Solved
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 attri...
Sarcophagus asked 26/6, 2014 at 15:27
6
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 c...
Pre asked 29/1, 2015 at 19:41
12
Solved
I have a list comprehension which approximates to:
[f(x) for x in l if f(x)]
Where l is a list and f(x) is an expensive function which returns a list.
I want to avoid evaluating f(x) twice for...
Suchlike asked 4/4, 2013 at 13:32
6
Solved
I’ve been reviewing code where some coders have been using redundant ternary operators “for readability.” Such as:
boolean val = (foo == bar && foo1 != bar) ? true : false;
Obviously it ...
Hamer asked 2/2, 2019 at 18:6
3
Solved
I have a long expression, its' not fitting in my screen, I want to write in several lines.
new_matrix[row][element] = old_matrix[top_i][top_j]+old_matrix[index_i][element]+old_matrix[row][in...
Yeaton asked 4/12, 2018 at 14:49
6
Solved
I have been wondering for some time whether it is allowable within best practice to refrain from using the containsKey() method on java.util.Map and instead do a null check on the result from get()...
Leah asked 30/1, 2013 at 9:53
4
Solved
I have been dissecting some code and I saw something I haven't seen before, and I was wondering if it is a good/bad practice and if it is normal.
Basically there is a header file with a class def...
Commingle asked 18/9, 2018 at 11:47
3
Solved
Trying to figure out the cleanest way to do the following:
I'm filtering some results twice, and I'm using Lodash filter to do so. Currently, my code looks like:
resultsOne = _.filter(results, fu...
Darladarlan asked 13/12, 2017 at 22:47
7
Solved
I'm trying to come up with an implementation for NotOfType, which has a readable call syntax. NotOfType should be the complement to OfType<T> and would consequently yield all elements that ar...
Bodoni asked 30/12, 2010 at 1:10
5
Solved
When you have a long fields in SQL query, how do you make it more readable?
For example:
public function findSomethingByFieldNameId($Id) {
$sql = "SELECT field1, field2, field3 as Field3_Somethi...
Peal asked 8/10, 2012 at 14:0
4
Solved
I wondered if there was any advantages of declaring templates function out of line vs in the class.
I'm trying to get a clear understanding of the pros and cons of the two syntax.
Here's an examp...
Populate asked 2/11, 2016 at 13:52
4
Solved
For a function/method contains many input parameters, does it make a difference if passing-in in different orders? If does, in what aspects (readability, efficiency, ...)? I am more curious about h...
Nureyev asked 2/1, 2014 at 10:39
9
Solved
Consider this line:
if (object.getAttribute("someAttr").equals("true")) { // ....
Obviously this line is a potential bug, the attribute might be null and we will get a NullPointerException. So w...
Fragile asked 8/6, 2009 at 8:48
1
Solved
I often see the following annotations in code:
@Getter
@Setter
public int test = 1;
I know I can create getter and setter methods using this annotations.
But which classes/library do I need to u...
Vagarious asked 3/3, 2016 at 15:32
4
Consider this function:
int get_result(int *result) {
int err = 0;
int number = 0;
if (result == NULL) {
printf("error: null input\n");
return -1;
}
err = get_number(&number);
...
Reins asked 22/8, 2015 at 16:43
1 Next >
© 2022 - 2025 — McMap. All rights reserved.