coding-style

Should instance variables not be used since they cause mulithreading problems?

不羁岁月 提交于 2019-12-13 19:55:05
问题 I understand that instance variables are not thread safe because they are stored on the heap. I am refactoring code in an ASP.NET single threaded application and I am trying to use instance variables more. My question is: do developers avoid using instance variables because of possible multi threading problems? (even if the app is not multi threaded now it may be in the future). I remember reading that instance variables should be used to improve design using composition and aggregation

Encapsulation with React child components

我是研究僧i 提交于 2019-12-13 19:27:23
问题 How should one access state (just state, not the React State) of child components in React? I've built a small React UI. In it, at one point, I have a Component displaying a list of selected options and a button to allow them to be edited. Clicking the button opens a Modal with a bunch of checkboxes in, one for each option. The Modal is it's own React component. The top level component showing the selected options and the button to edit them owns the state, the Modal renders with props

Is it clearer to sleep near a function call in a loop or in the function call itself?

你离开我真会死。 提交于 2019-12-13 18:43:25
问题 Is it clearer to sleep near a function call in a loop or in the function call itself? Personally I lean toward sleeping near the call rather than in the call, because there is nothing about "getApple()" that implies that it should sleep for some amount of time before returning the apple. I think it would be clearer to have: for ( int i = 0; i < 10; ++i ) { getApple(); sleep() } than... for ( int i = 0; i < 10; ++i ) { getApple(); } Apple getApple() { sleep(1); return new Apple(); } Of course,

“The input/output library <stdio.h> shall not be used.”

喜你入骨 提交于 2019-12-13 18:14:36
问题 I'm reading the JSF AV C++ Coding Standards and the rule 22 says: AV Rule 22 (MISRA Rule 124, Revised) The input/output library <stdio.h> shall not be used. Is there any reason to not use <stdio.h> ? I know that these rules are for C++ and we can use <iostream> ... but what's wrong with <stdio.h> ? 回答1: Every now and then, there are questions like this, about why some coding standard mandates this or that. The correct answer should always be: Whatever the authors of that coding standard

SQL Table / Sub-Query Alias Conventions

风格不统一 提交于 2019-12-13 16:18:24
问题 I've been writing SQL for a number of years now on various DBMS (Oracle, SQL Server, MySQL, Access etc.) and one thing that has always struck me is the seemingly lack of naming convention when it comes to table & sub-query aliases. I've always read that table alises are the way to go and although I haven't always used them, when I do I'm always stuck between what names to use. I've gone from using descriptive names to single characters such as 't', 's' or 'q' and back again. Take for example

Using comma to prevent the need for brace pair

强颜欢笑 提交于 2019-12-13 16:08:23
问题 Sometimes, when I have a multi-case if , or a very simple for , with only two statements, I will forgo braces, instead using the comma. Is this a bad exploitation of the feature, and is it ugly and bad form? Or is it an acceptable way to save time and space? For example: if (something) b = y, c = z--; instead of: if (something) { b = y; c = z--; } 回答1: It's indeed a clever way to use that syntactic feature of most C-like languages. Personally, I try to stay the least ambiguous as possible

Winform customize listbox item

给你一囗甜甜゛ 提交于 2019-12-13 15:44:30
问题 I have a listbox that should display data that contains 2 fields: time and a message. Instead of displaying 1 line of text, I want each item to be displayed as 2 lines - 1st line is the time and the 2nd line is the message, where each line has a different style. How can I do this? I can bind the object array to the listbox, but how do I style it? Thanks for your answers. 回答1: I'll just formally post an answer earlier left in a comment. You'll need to use the DrawMode property, there's a good

Returning result via Output-parameter, c++ coding standard [duplicate]

﹥>﹥吖頭↗ 提交于 2019-12-13 15:21:08
问题 This question already has answers here : best practice for parameters? (5 answers) Closed 6 years ago . I have a member function in my class like this: int MyClass::m_Func(int& val); in which, I do some operation and put the result in val . And depending upon the result of the operation, I returned different values from the function. Like, if it is successful, I return 0 or other values if any error occurs. One of my friend told me that it is not a good practice to pass a reference of a

Enforcing using the class name whenever a shared member is accessed

懵懂的女人 提交于 2019-12-13 14:43:28
问题 We have a coding standard that says all shared (static) fields and methods must be called with the class name. E.g. NameOfClass.whatever Rather then whatever Is there a tool that we can use to check this is in fact the case? (Likewise for modules) Sorry I should have make it clearer we are using VB.NET. This is a bigger example of what I mean. Public Class Class1 Public Shared Sub SharedMethod() End Sub Public Shared sharedField As Integer Public Sub NotSharedMethod() 'this next line shold be

correct style for element-wise operations on lists without numpy (python)

谁说胖子不能爱 提交于 2019-12-13 14:32:46
问题 I would like to operate on lists element by element without using numpy, for example, i want add([1,2,3], [2,3,4]) = [3,5,7] and mult([1,1,1],[9,9,9]) = [9,9,9] , but i'm not sure which way of doing is it considered 'correct' style. The two solutions i came up with were def add(list1,list2): list3 = [] for x in xrange(0,len(list1)): list3.append(list1[x]+list2[x]) return list3 def mult(list1, list2): list3 = [] for x in xrange(0,len(list1)): list3.append(list1[x]*list2[x]) return list3 def