coding-style

Python relative import with more than two dots

女生的网名这么多〃 提交于 2019-12-05 05:25:31
Is it ok to use a module referencing with more than two dots in a path? Like in this example: # Project structure: # sound # __init__.py # codecs # __init__.py # echo # __init__.py # nix # __init__.py # way1.py # way2.py # way2.py source code from .way1 import echo_way1 from ...codecs import cool_codec # Do something with echo_way1 and cool_codec. UPD: Changed the example. And I know, this will work in a practice. But is it a common method of importing or not? From PEP8 : Absolute imports are recommended, as they are usually more readable and tend to be better behaved (or at least give better

How to remove 3D border in IE8 with DOCTYPE XHTML?

☆樱花仙子☆ 提交于 2019-12-05 04:58:33
The problem: Here is what I do body { border: 0; } as was suggested here: Removing border from WebBrowser control But this only works when we use the following doctype: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> When doctype is changed to <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"> the nasty border won't go away! But I need the XHTML doctype in order for "position: fixed" to work in IE. Any suggestions? The code: HTML: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"> <html> <head> <title>Borders, Go

bitwise indexing in C?

大憨熊 提交于 2019-12-05 04:50:00
I'm trying to implement a data compression idea I've had, and since I'm imagining running it against a large corpus of test data, I had thought to code it in C (I mostly have experience in scripting languages like Ruby and Tcl.) Looking through the O'Reilly 'cow' books on C, I realize that I can't simply index the bits of a simple 'char' or 'int' type variable as I'd like to to do bitwise comparisons and operators. Am I correct in this perception? Is it reasonable for me to use an enumerated type for representing a bit (and make an array of these, and writing functions to convert to and from

Class method and instance method with the same name in Objective-C

十年热恋 提交于 2019-12-05 04:47:43
I have a solution for a notification problem which works well, but I'm afraid might be a bad idea. I have a notification that needs to be handled by each instance of a class and by the class itself. To handle this, I'm registering for a notification by both the class and instances of the class. Because it's the exact same notification, I've named the class and instance method the same. This follows the standard we've set for how notification handlers are named. Is this a bad idea? Is there some hidden got'ca that I'm missing. Will I be confusing the heck out of future developers? + (void

what is the overhead of passing a reference?

蓝咒 提交于 2019-12-05 04:45:46
how expensive is it to access a member variable when the getter in question return a reference? for example, if you have a class that needs to use such an accessor fairly often, how much more efficient would it be to store said reference in the class that needs to use it and simply initialise it once? Regarding complexity, returning or passing a reference is just like passing a pointer. Its overhead is equivalent to passing an integer the size of a pointer, plus a few instructions . In short, that is as fast as is possible in nearly every case. Builtin types (e.g. int, float) less than or

Checkstyle rule to prevent invocation of some methods and constructors

余生长醉 提交于 2019-12-05 04:41:43
Is it possible to use Checkstyle to forbid usage of some constructors or method that use system-dependent defaults (locale, charset, etc..). I prefer to enforce a policy where the programmer should be explicit about system-dependent values. So I consider the following items to be dangerous: all the constructors of java.io.FielWriter using system-dependent encoding the OutputStreamWriter(OutputStream os) constructor of java.io.OutputStreamWriter using system-dependent encoding the java.lang.String.toLowerCase() method using system default locale The java.util.Calendar.getInstance() method using

What is the meaning of leading and trailing underscores in Linux kernel identifiers?

 ̄綄美尐妖づ 提交于 2019-12-05 04:31:55
I keep running across little conventions like __KERNEL__ . Are the __ in this case a naming convention used by kernel developers or is it a syntax specific reason for naming a macro this way? There are many examples of this throughout the code. For example some functions and variables begin with an _ or even __ . Is there a specific reason for this? It seems pretty widely used and I just need some clarification as to whether these things have a syntactical purpose or is it simply a naming convention. Furthermore I see lots of user declared types such as uid_t. Again I assume this is a naming

Protected properties prefixed with underscores

。_饼干妹妹 提交于 2019-12-05 04:30:36
Like: public $foo = null, $bar = 10; protected $_stuff = null, $_moreStuff = 5; A lot of people seem to do this. Why? Isn't this inconsistent naming (like some PHP functions are :))? It really comes down to one thing: personal preference. I, personally, am also one who uses that naming convention. Prefixing anything that is protected or private with an underscore, be it a variable or a function, lets myself and any other programmer who I regularly work with know that that variable is global and will not be accessible outside of the current class/context. An example that helps clarify the use

do interfaces belong in files of their own

ぐ巨炮叔叔 提交于 2019-12-05 03:59:14
As as rule of thumb I generally put classes in a file of their own. Visual studio seems to encourage this but what is appropriate with regards to interfaces? e.g. I have Class Foo that implements interface Bar public interface IBar { } public class Foo : IBar { } it seems natural to group these within the same file until another class implements the interface but to dedicate a file to 2 lines code seems excessive but correct. What is appropriate? I would split them into 2 files. I often found classes starting to go unmanageable when they are not in their own files. Imagine trying to find class

McCabe Cyclomatic Complexity for switch in Java

五迷三道 提交于 2019-12-05 03:43:31
I am using a switch statement with 13 cases, each case only has an one line return value. McCabe paints this in red. Is there an easier way to write a big switch statement? It doesn't seem complex to read, but I don't like the default setting turning red. If other people use the same tool on my code and see red stuff they might think I'm stupid :-) Edit: I'm mapping different SQL-Types to my own more abstract types, therefore reducing the total amount of types. case Types.TIME: return AbstractDataType.TIME; case Types.TIMESTAMP: return AbstractDataType.TIME; case Types.DATE: return