coding-style

Early returns vs nested positive if statements

旧巷老猫 提交于 2019-12-06 21:57:05
问题 Here is some hypothetical code sample: if (e.KeyCode == Keys.Enter) { if (this.CurrentElement == null) { return false;} if (this.CurrentElement == this.MasterElement) { return false;} if (!Validator.Exist (this.CurrentElement)) { return false;} if (!Identifier.IsPictureElement (this.CurrentElement)) { return false;} this.FlattenObjects(this.CurrentElement); } VS if (e.KeyCode == Keys.Enter) { if (this.CurrentElement != null) { if (this.CurrentElement != this.MasterElement) { if (Validator

McCabe Cyclomatic Complexity for switch in Java

帅比萌擦擦* 提交于 2019-12-06 21:00:13
问题 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

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

╄→尐↘猪︶ㄣ 提交于 2019-12-06 20:33:40
问题 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 6 years ago . 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

Jade: declare a variable over multiple lines

微笑、不失礼 提交于 2019-12-06 20:29:17
问题 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

How bad is it to put javascript outside of the header?

余生长醉 提交于 2019-12-06 20:16:23
问题 The question pretty much already says everything. I'm starting to add some features to my weekend project. It's a small app for me and a couple of friends, as we're exchange students it's kinda useful for us. But the thing is the following, I'm doing this in php and structuring everything with includes so i can get the code separated. Some of these pieces of code are dependent on javascripts snipets, so how bad is it to put a javascript in the middle of the body? Or should i just make double

Java coding style, local variables vs repeated method calls

穿精又带淫゛_ 提交于 2019-12-06 19:45:31
问题 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)

Java: instantiate variables in loop: good or bad style?

点点圈 提交于 2019-12-06 19:04:27
问题 Ive got one simple question. Normally I write code like this: String myString = "hello"; for (int i=0, i<10; i++) { myString = "hello again"; } Because I think the following would not be good style cause it would create too many unnecessary objects. for (int i=0, i<10; i++) { String myString = "hello again"; } Is this even correct? Or is this just the case when Ive got an explicit object like an object from a class I created? What if it was a boolean or an int? What is better coding style?

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

会有一股神秘感。 提交于 2019-12-06 18:27:46
问题 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 } 回答1: 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

Ordering columns in database tables

纵然是瞬间 提交于 2019-12-06 18:12:36
问题 When it comes to column order in DB tables, are there any standards or at least best practices? Here's a handmade convention that I follow: primary key (i.e. id ); unique columns (i.e. email , ssn ); foreign keys (i.e. article ); columns holding user generated data (i.e. first_name , last_name ); columns holding system generated data; non-boolean (i.e. password_hash ); boolean (i.e. deleted , verified ) timestamp columns (i.e. created_at ); These leave many questions unanswered, though, so I

Export Visual Studio's 'Code Style settings' as .editorconfig

橙三吉。 提交于 2019-12-06 17:40:36
问题 Our team works with Visual Studio 2017 Professional. I've been trying to unify the Code Style across the team and apparently the industry standard right now is to use .editorconfig files. Even Visual Studio in it's settings windows suggests to use that configuration file and links to a useful page on how to write an editorconfig file. but I don't want to write all the settings that I already have configured in VS by hand. I would like a tool that exports those settings as a .editorconfig file