conventions

One table vs multiple tables

和自甴很熟 提交于 2019-12-04 12:35:05
I have the following tables: - posts - files - events - documents Every post, file, event, document can have comments. What is the better database scheme for this, and why ? First solution comments table (comment_id, author_id, comment) 4 tables to create relations (posts_comments(post_id, comment_id), files_comments(file_id, comment_id), events_comments(event_id, comment_id), documents_comments(document_id, comment_id)) Second solution comments table (comment_id, author_id, comment) items_comments (comment_id, parent_type (enum['post', 'file', 'event', 'document']), parent_id) What is a

Python 3 object construction: which is the most Pythonic / the accepted way?

不问归期 提交于 2019-12-04 11:06:36
问题 Having a background in Java, which is very verbose and strict, I find the ability to mutate Python objects as to give them with fields other than those presented to the constructor really "ugly". Trying to accustom myself to a Pythonic way of thinking, I'm wondering how I should allow my objects to be constructed . My instinct is to have to pass the fields at construction time , such as: def __init__(self, foo, bar, baz=None): self.foo = foo self.bar = bar self.baz = baz But that can become

Can I make vim accept \b rather than just \< and \>?

为君一笑 提交于 2019-12-04 03:30:06
问题 I've just read this: In Vim, how do you search for a word boundary character, like the \b in regexp? and I was wondering - can't I make vim recognize \b also, somehow? 回答1: Since Vim's regex flavor treats \b as a backspace character, and there is no chance re-defining this shorthand construct, you can only make it work with a PCRE regex engine that can be used with Vim the way described at Perl compatible regular expressions Vim Tips Wiki. This is the description from that page: Verify with

python code convention using pylint

孤者浪人 提交于 2019-12-04 02:31:29
I'm trying out pylint to check my source code for conventions. Somehow some variable names are matched with the regex for constants ( const-rgx ) instead of the variable name regex ( variable-rgx ). How to match the variable name with variable-rgx ? Or should I extend const-rgx with my variable-rgx stuff? e.g. C0103: 31: Invalid name "settings" (should match (([A-Z_][A-Z1-9_]*)|(__.*__))$) Somehow some variable names are matched with the regex for constants (const-rgx) instead of the variable name regex (variable-rgx). Are those variables declared on module level? Maybe that's why they are

Which namespace does operator<< (stream) go to?

醉酒当歌 提交于 2019-12-03 23:29:45
If I have have some overloaded ostream operators, defined for library local objects, is its okay for them to go to std namespace? If I do not declare them in std namespace, then I must use using ns:: operator << . As a possible follow-up question, are there any operators which should go to standard or global namespace? According to Koenig Lookup (C++ Standard 3.4.2) operator<< will be searched in namespaces of arguments. No need to declare it in std namespace. Herb Sutter operator<<( ..., MyClass ) should go in the same namespace as MyClass . You should think of it as part of the interface of

Where to declare class constants?

空扰寡人 提交于 2019-12-03 22:24:44
I'm using class members to hold constants. E.g.: function Foo() { } Foo.CONSTANT1 = 1; Foo.CONSTANT2 = 2; This works fine, except that it seems a bit unorganized, with all the code that is specific to Foo laying around in global scope. So I thought about moving the constant declaration to inside the Foo() declaration, but then wouldn't that code execute everytime Foo is constructed? I'm coming from Java where everything is enclosed in a class body, so I'm thinking JavaScript might have something similar to that or some work around that mimics it. All you're doing in your code is adding a

Should one use < or <= in a for loop [closed]

天大地大妈咪最大 提交于 2019-12-03 18:26:32
问题 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 months ago . If you had to iterate through a loop 7 times, would you use: for (int i = 0; i < 7; i++) or: for (int i = 0; i <= 6; i++) There are two considerations: performance readability For performance I'm assuming Java or C#. Does it matter if "less than" or "less than or equal to"

Clojure code static analysis tools

给你一囗甜甜゛ 提交于 2019-12-03 12:36:27
Is there a tool to run code convention tests in clojure? For example, make sure function names don't have any capital letters or keywords don't have any underscores in them. Two useful Leiningen plugins I learned about recently: lein-bikeshed lein-kibit Venantius Late to the party here. Seconding noahlz , the three main static analysis tools that I use on a regular basis are lein-bikeshed , lein-kibit , and Eastwood , though I also use yagni . Each of these has different strengths. Bikeshed is good for general code cleanup but is mostly focused on style (e.g. making sure lines aren't too long,

List of de facto standard keyboard shortcuts for Windows apps?

旧巷老猫 提交于 2019-12-03 10:19:54
问题 Let's say I'm developing a new desktop application for Windows. Is there a list somewhere that I can consult (either from Microsoft or a 3rd party) of keyboard shortcuts that all Windows applications should support? (Note: When I say "all Windows applications" here, I really mean "all Windows applications where a particular keyboard shortcut makes sense." For example, a standard "Begin debug session" shortcut might make sense across IDE applications such as Visual Studio and Eclipse, but not

Python 3 object construction: which is the most Pythonic / the accepted way?

纵然是瞬间 提交于 2019-12-03 07:01:07
Having a background in Java, which is very verbose and strict, I find the ability to mutate Python objects as to give them with fields other than those presented to the constructor really "ugly". Trying to accustom myself to a Pythonic way of thinking, I'm wondering how I should allow my objects to be constructed . My instinct is to have to pass the fields at construction time , such as: def __init__(self, foo, bar, baz=None): self.foo = foo self.bar = bar self.baz = baz But that can become overly verbose and confusing with many fields to pass. To overcome this I assume the best method is to