coding-style

Idiomatic Python logging: format string + args list vs. inline string formatting - which is preferred?

折月煮酒 提交于 2019-12-05 01:26:54
Is it advantageous to call logging functions with format string + args list vs. formatting inline? I've seen (and written) logging code that uses inline string formatting: logging.warn("%s %s %s" % (arg1, arg2, arg3)) and yet I assume it's better (performance-wise, and more idiomatic) to use: logging.warn("%s %s %s", arg1, arg2, arg3) because the second form avoids string formatting operations prior to invoking the logging function. If the current logging level would filter out the log message, no formatting is necessary, reducing computing time and memory allocations. Am I on the right track

Java coding style, local variables vs repeated method calls

寵の児 提交于 2019-12-05 01:08:13
I prefer to use local variables rather than multiple calls to the same method. /* * I prefer this */ Vehicle vehicle = person.getVehicle() if (vehicle instanceof Car) { Car car = (Car) vehicle; car.openSunroof(); } else if (vehicle instanceof Bike) { Bike bike = (Bike) vehicle; bike.foldKickstand(); } /* * Rather than this */ if (person.getVehicle() instanceof Car) { Car car = (Car) person.getVehicle(); car.openSunroof(); } else if (person.getVehicle() instanceof Bike) { Bike bike = (Bike) person.getVehicle(); bike.foldKickstand(); } I believe that the first way is going to perform a tiny bit

Checkstyle rules for Google Java Style

佐手、 提交于 2019-12-05 00:57:16
Is there a Checkstyle rule file with the Google Java Style ? The checkstyle team added it several days ago. Here it is : https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml Markus Schulte If you have a maven-project, you can easily integrate google_checks (you have to use at least maven-checkstyle-plugin version 2.17) <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <version>2.17</version> <configuration> <configLocation>google_checks.xml</configLocation> </configuration> </plugin> Executing checkstyle

Ruby convention for accessing first/last element in array [closed]

守給你的承諾、 提交于 2019-12-05 00:33:45
This is a question about conventions. The two sets of commands below return identical results. a = [1, 2, 3] a.first # => 1 a[0] # => 1 a.last # => 3 a[-1] # => 3 Which of these is preferred in Ruby, the explicit index or the functions? Assuming, of course, that this is in code which always accesses the first or last element. Note: I've been thinking about the cycles each would take. Because first and last accept parameters, they will have a little more overhead, but I don't know if that affects what the community prefers. Thanks! EDIT If you read the comments on this post, there was a big

How to make a fancy transparent menu like the “share menu” in Android gallery?

筅森魡賤 提交于 2019-12-05 00:26:06
问题 On my Android 2.2.2 device the gallery looks really nice. What I would love to do in my own app is to press a button and then show a menu that looks like this: Is this using any standard Android themes / styles? Does anybody know of an example code to have a menu like this? Edit: I figured out that one could mimic this menu with a Dialog. To simplify things I'm not using a ListView in this example, just a single TextView entry for the dialog: <LinearLayout xmlns:android="http://schemas

Jade: declare a variable over multiple lines

我只是一个虾纸丫 提交于 2019-12-05 00:16:50
I have a jade variable declared like this: BUTTONS = { more_blue: {caption: BUTTONS_CAPTIONS.more, style: BUTTONS_STYLES.blue}, more_red: {caption: BUTTONS_CAPTIONS.more, style: BUTTONS_STYLES.red}, see: {caption: BUTTONS_CAPTIONS.see, style: BUTTON_STYLE_PHOTOS}, see_photos: {caption: BUTTONS_CAPTIONS.see_photos, style: BUTTON_STYLE_PHOTOS}, program : {caption: BUTTONS_CAPTIONS.program, style: BUTTON_STYLE_PROGRAM}, see_program : {caption: BUTTONS_CAPTIONS.see_program, style: BUTTON_STYLE_PROGRAM} } but I would like it to be more readable like this: BUTTONS = { more_blue: {caption: BUTTONS

Style triggers in Silverlight

青春壹個敷衍的年華 提交于 2019-12-05 00:07:19
问题 I am trying to use style triggers in silverlight like so: <Path Canvas.Top="20" Stroke="#FF808080" Data="M 0,20 20,0 40,20 Z" StrokeLineJoin="Round"> <Path.Style> <Style TargetType="{x:Type Path}"> <Setter Property="Fill" Value="DarkGray"/> <Style.Triggers> <DataTrigger Binding="{Binding ElementName=userControl, Path=PumpRunning}" Value="True"> <Setter Property="Fill" Value="DarkGreen"/> </DataTrigger> </Style.Triggers> </Style> </Path.Style> </Path> I want to do this so that the fill value

If 'else' is about to happen anyway should it be declared or not? [duplicate]

▼魔方 西西 提交于 2019-12-04 23:54:17
This question already has answers here : Closed 9 years ago . Possible Duplicate: Should ‘else’ be kept or dropped in cases where it’s not needed? When a = 0 This: var foo = function() { if (a != 0) return true return false } Or this: var bar = function() { if (a != 0) return true else return false } It gets optimized at compile time anyway, so no runtime difference. As usual, you can argue about style. My 50 cents: the first variant (no explicit else) is nicer because it's less code doing exactly the same. Of course, in this case, you would do return a != 0; ... but I think the question is

Why isn't main defined `main(std::vector<std::string> args)`?

核能气质少年 提交于 2019-12-04 23:39:36
This question is only half tongue-in-cheek. I sometimes dream of a world without naked arrays or c strings. If you're using c++, shouldn't the preferred definition of main be something like: int main(std::vector<std::string> args) ? There are already multiple definitions of main to choose from, why isn't there a version that is in the spirit of C++? A concern that keeps coming back to my mind is that once you allow complex types, you end up with the risk of exceptions being thrown in the type's constructor. And, as the language is currently designed, there's absolutely no way for such an

Complete list of default values for JSHint options?

*爱你&永不变心* 提交于 2019-12-04 23:37:46
Where can I get the complete list of JSHint default options. I tried searching online but couldn't find anything. EDIT: I mean a list of default values for all options, in case it wasn't clear :) Mikhail Chernykh You can look on boolOptions , valOptions and invertedOptions objects directly in jshint sources: https://github.com/jshint/jshint/blob/master/examples/.jshintrc If you are confused with comments, you can refer to options section in jshint help: http://jshint.com/docs/options/ J.D. Actually, that page contains the list of default options, and that file mentioned in @netme's answer has