coding-style

Code style - “flattening” a package's namespace

 ̄綄美尐妖づ 提交于 2019-12-07 09:33:56
问题 My package hierarchy: InstrumentController/ __init__.py instruments/ __init__.py _BaseInstrument.py Keithley2000.py # etc... The contents of the instrument files: # _BaseInstrument.py class _BaseInstrument(object): """Base class for instruments""" # etc... # Keithley2000.py from InstrumentController.instruments._BaseInstrument import _BaseInstrument class Keithley2000(_BaseInstrument): # etc... I want my users to be able to access the classes without having to delve into a hierarchy of

mysql should i use apostrophe in mysql queries?

会有一股神秘感。 提交于 2019-12-07 08:17:05
问题 What is the correct way of writing a query to a MySQL database on numeric data-types: SELECT * FROM accounts WHERE id = 5; or SELECT * FROM accounts WHERE id = '5'; Mainly I prefer the last one, using ' because it is more consistent with text data-types. Does it effect the performance? 回答1: Quotes are for strings, MySQL is going to read those quotes and then cast it to an integer, this is slower then just handing it an int to begin with. Honestly the performance difference is minor, but it is

How to handle HUGE SQL strings in the source code

别来无恙 提交于 2019-12-07 08:10:29
问题 I am working on a project currently where there are SQL strings in the code that are around 3000 lines. The project is a java project, but this question could probably apply for any language. Anyway, this is the first time I have ever seen something this bad. The code base is legacy, so we can suddenly migrate to Hibernate or something like that. How do you handle very large SQL strings like that? I know its bad, but I don't know exactly what is the best thing to suggest for a solution. 回答1:

proper way to construct HTML based on AJAX input

不羁岁月 提交于 2019-12-07 08:00:23
问题 So I'm developing this web application in Django. The exact web framework doesn't matter, but the point is: We have a nice separation between code, data and the actual HTML. The further we go however, the more we find we'd like to keep on a single web page and make the interface respond to user actions via AJAX requests. Now I find myself writing all these handler functions which expect a particular input from the AJAX request and construct large parts of the page by basically concatenating

if (condition) continue; OR if (!condition) { … }? (style preference)

泪湿孤枕 提交于 2019-12-07 07:44:38
问题 I know this is a matter of style, hence the subjective tag. I have a small piece of code, with two nested conditions. I could code it in two ways, and I'd like to see how more experienced developers think it should look like. Style 1 : while (!String.IsNullOrEmpty(msg = reader.readMsg())) { RaiseMessageReceived(); if (parseMsg) { ParsedMsg parsedMsg = parser.parseMsg(msg); RaiseMessageParsed(); if (processMsg) { process(parsedMsg); RaiseMessageProcessed(); } } } Style 2: while (!String

Why should I use <ARGV> or <> instead of <STDIN> in Perl?

别说谁变了你拦得住时间么 提交于 2019-12-07 07:43:25
问题 Quoting from Perl::Critic::Policy::InputOutput::ProhibitExplicitStdin Perl has a useful magic filehandle called *ARGV that checks the command line and if there are any arguments, opens and reads those as files. If there are no arguments, *ARGV behaves like *STDIN instead. This behavior is almost always what you want if you want to create a program that reads from STDIN. This is often written in one of the following two equivalent forms: while (<ARGV>) { # ... do something with each input line

Stop PhpStorm from adding a new line after function declaration when arguments split across multiple lines

青春壹個敷衍的年華 提交于 2019-12-07 07:36:27
问题 In my PhpStorm 8.0.3 code style, I have set it to add a new line after a function declaration, which works fine. Problem is now I'm in a new project that follows the PSR-2 Standards, which say that the opening brace of a function MUST be placed in the same line that the closing parenthesis of the function arguments when these split across multiple lines, as you can see here. I want this when arguments split across multiple lines... public function myMethod( MyClass $arg1, $arg2 = null ) { //

What is the perfect way to write “return” in a method

混江龙づ霸主 提交于 2019-12-07 07:16:38
问题 I don't like methods have several return lines. So I created a return value with string result - and in every condition I write result = something... But when I write "try-catch" mechanism, I have to set public string result . Because, if I return a result in try, compiler will launch error, and says not all codes have return value. If I write result = string.Empty to end of the method, resharper says, it's not reachable code. So, here an example, and here is my question; "What is the perfect

Whats the reasoning behind the different brace forms? [closed]

孤者浪人 提交于 2019-12-07 06:27:17
问题 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 2 years ago . I'm reading through the Zend Framework coding standards, where they state that curly brace after a Class definitions should be on the next line, the "one true brace form". class MyClass { function.... } I usually have the braces on the same line: class OtherClass { function .

When to use which - multiple methods, multiple parameters, or an options parameter

南笙酒味 提交于 2019-12-07 04:09:37
问题 This question is coming from a javascript point of view, but it certainly could apply to other languages. I have been running into this more and more lately, and was wondering if there was a best practice, or at least good design standard, for when how to build your methods. The obvious options that I see are as follows, along with a trivial example for each Multiple methods: this.makeGetRequest = function(controller){...} this.makeSynchronousGetRequest = function(controller){...} this