coding-style

Java array convention: String[] args vs. String args[]

徘徊边缘 提交于 2019-12-28 12:00:43
问题 I am currently teaching students as a tutor programming conventions. I've told them that they can find most conventions in the Oracle Code Conventions. In my last tutorial a student asked if: public static void main(String args[]) or public static void main(String[] args) is written by convention or if there is a difference. I have never seen the first version before, so I'm very sure that the second one is a convention. But I don't have a source for that. Can you give me a source (preferably

Named blocks to limit variable scope: good idea?

a 夏天 提交于 2019-12-28 08:11:40
问题 For years, I've been using named blocks to limit the scope of temporary variables. I've never seen this done anywhere else, which makes me wonder if this is a bad idea. Especially since the Eclipse IDE flags these as warnings by default. I've used this to good effect, I think, in my own code. But since it is un-idiomatic to the point where good programmers will distrust it when they see it, I really have two ways to go from here: avoid doing it, or promote it, with the hope that it will

Named blocks to limit variable scope: good idea?

不问归期 提交于 2019-12-28 08:11:12
问题 For years, I've been using named blocks to limit the scope of temporary variables. I've never seen this done anywhere else, which makes me wonder if this is a bad idea. Especially since the Eclipse IDE flags these as warnings by default. I've used this to good effect, I think, in my own code. But since it is un-idiomatic to the point where good programmers will distrust it when they see it, I really have two ways to go from here: avoid doing it, or promote it, with the hope that it will

Bytewise reading of memory: “signed char *” vs “unsigned char *”

送分小仙女□ 提交于 2019-12-28 05:38:15
问题 One often needs to read from memory one byte at a time, like in this naive memcpy() implementation: void *memcpy(void *dest, const void *src, size_t n) { char *from = (char *)src; char *to = (char *)dest; while(n--) *to++ = *from++; return dest; } However, I sometimes see people explicitly use unsigned char * instead of just char * . Of course, char and unsigned char may not be equal. But does it make a difference whether I use char * , signed char * , or unsigned char * when bytewise reading

Attributes initialization/declaration in Python class: where to place them?

可紊 提交于 2019-12-28 05:16:17
问题 I was wondering what was the best practice for initializing object attributes in Python, in the body of the class or inside the __init__ function? i.e. class A(object): foo = None vs class A(object): def __init__(self): self.foo = None 回答1: If you want the attribute to be shared by all instances of the class, use a class attribute: class A(object): foo = None This causes ('foo',None) to be a (key,value) pair in A.__dict__ . If you want the attribute to be customizable on a per-instance basis,

Importing modules in Python - best practice

落花浮王杯 提交于 2019-12-28 04:54:13
问题 I am new to Python as I want to expand skills that I learned using R. In R I tend to load a bunch of libraries, sometimes resulting in function name conflicts. What is best practice in Python. I have seen some specific variations that I do not see a difference between import pandas , from pandas import * , and from pandas import DataFrame What are the differences between the first two and should I just import what I need. Also, what would be the worst consequences for someone making small

Why use a for loop instead of a while loop? [duplicate]

风流意气都作罢 提交于 2019-12-28 04:54:08
问题 This question already has answers here : Closed 9 years ago . Possible Duplicates: Iterate with for loop or while loop? Loops in C - for() or while() - which is BEST? When should one use a for loop instead of a while loop? I think the following loops are identical, except for their syntax. If so, then why choose one over the other? int i; for (i = 0; i < arr.length; i++) { // do work } int i = 0; while (i < arr.length) { // do work i++; } 回答1: In your case, you don't gain much besides one

Should a collection of constants be placed in a class or interface?

試著忘記壹切 提交于 2019-12-28 03:46:06
问题 If I have a collection of static constants that I want to declare centrally so that they can be shared among various projects should they be put in a class or interface (Java). In the past I have seen them mostly put in a class but I started thinking that since the class will not and should not be instantiated maybe they would be better in an interface, but then again the interface should not be implemented by any classes, e.g. public class ErrorCodes { public static final String ERROR_1 = "

Is there a good reason to use upper case for SQL keywords? [closed]

吃可爱长大的小学妹 提交于 2019-12-28 03:23:50
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago . The default seems to be upper case, but is there really any reason to use upper case for keywords? I started using upper case because I was just trying to match what SQL Server gives me whenever I tried to create something, like a new stored procedure. But then, I felt

Applying Styles To ListItems in CheckBoxList

限于喜欢 提交于 2019-12-28 03:01:34
问题 How can styles be applied to CheckBoxList ListItems. Unlike other controls, such as the Repeater where you can specify <ItemStyle> , you can't seem to specify a style for each individual control. Is there some sort of work around? 回答1: You can add Attributes to ListItems programmatically as follows. Say you've got a CheckBoxList and you are adding ListItems. You can add Attributes along the way. ListItem li = new ListItem("Richard Byrd", "11"); li.Selected = false; li.Attributes.Add("Style",