coding-style

Best practice on ending if…else statement without else condition

烂漫一生 提交于 2019-12-04 19:28:57
问题 What is the best practice to end an if...else statement without an else condition? Consider the following code: $direction = $_POST['direction']; //Up or down if ($direction == "up") { code goes here... } elseif ($direction == "down") { code goes here... } else { //do nothing? } As you can see, there's only 2 condition; either up or down and the else statement doesn't really have a purpose unless you want it to display an error message. Most of the time I see programmers simply put the else

Are there any HTML coding conventions/style/standard [closed]

浪尽此生 提交于 2019-12-04 19:21:01
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . I mean to name ids, names, values, etc? 回答1: While I don't think there is a single, accepted naming conventions for naming HTML elements, you might find the following article helpful. The content starting on page two is probably most helpful. Good luck! The Meaning of Semantics Take II: Naming Conventions for

Missing Term Arithmetic Progression - Clean up my code

梦想的初衷 提交于 2019-12-04 18:20:42
I just tried a little online programming quiz that asked me to solve this problem as quickly as possible. I got the right answer but I know it isn't pretty. I'm trying to become a better programmer and write cleaner, more efficient code so please give me some tips. I've included the description below. PS I think this algorithm fails for the case N=3 # Enter your code here. Read input from STDIN. Print output to STDOUT import sys N= int(sys.stdin.readline()) stringdata = sys.stdin.readline() array = stringdata.split(' ') diff1=[0]*(N-1) diff2 = [0]*(N-2) index = 0 diff = 0 for i in range(0,len

Rails inline Javascript and Best Practices

≯℡__Kan透↙ 提交于 2019-12-04 18:19:08
问题 I'm kinda new to using Rails, and an app I am working on is progressing well - however I'm looking though the generated HTML and noticed things like... <script type="text/javascript"> //<![CDATA[ Droppables.add(...); //]]> </script> Sprinkled around the HTML, which of course matches up with places where I use: <%= drop_receiving_element ... %> What I'm wondering is... is there a better way to do this, or make it cleaner? Some of these script tags are coming from partials so putting them at

Comma-first JS formatter

◇◆丶佛笑我妖孽 提交于 2019-12-04 18:15:33
问题 Do you know of a JS formatter that will support the comma-first coding style? var a = 'ape' , b = 'bat' , c = 'cat' , d = 'dog' , e = 'elf' , f = 'fly' , g = 'gnu' , h = 'hat' , i = 'ibu' ; So far, I've looked at JS Beautifier & SourceFormatX but couldn't find an option for it. 回答1: I modified the jsbeautifier code a little here: http://jsfiddle.net/RabTN/29/ press doit to see the beautified code. I specifically modified line 1080: if (flags.var_line) { if (token_text === ',') { if (flags.var

objective c coding guidelines

我的梦境 提交于 2019-12-04 17:42:59
问题 Is there any pdf which tells about coding guidelines in objective C. For Example... 1. Breaking the function names - checkIfHitTheTrack. 2. member variables must be like - mVariableName. 3. Giving better names to subclass - ? Please share the related links... 回答1: I would start with these: Apple's Coding Guidelines for Cocoa Google's Objective-C Style Guide 回答2: Take a look at Objective-C Beginner's Guide. 来源: https://stackoverflow.com/questions/2543090/objective-c-coding-guidelines

Is using static private methods really faster/better than instance private methods?

左心房为你撑大大i 提交于 2019-12-04 17:34:32
What I'm asking is whether there is a difference between doing this: public Something importantBlMethod(SomethingElse arg) { if (convenienceCheckMethod(arg)) { // do important BL stuff } } private boolean convenienceCheckMethod(SomethingElse arg) { // validate something } And this: public Something importantBlMethod(SomethingElse arg) { if (convenienceCheckMethod(arg)) { // do important BL stuff } } private static boolean convenienceCheckMethod(SomethingElse arg) { // validate something } I actually use option 1 as it seems more natural to me. So is there a style/convention/performance

When to use Properties and Methods?

巧了我就是萌 提交于 2019-12-04 17:15:26
问题 I'm new to the .NET world having come from C++ and I'm trying to better understand properties. I noticed in the .NET framework Microsoft uses properties all over the place. Is there an advantage for using properties rather than creating get/set methods? Is there a general guideline (as well as naming convention) for when one should use properties? 回答1: It is pure syntactic sugar. On the back end, it is compiled into plain get and set methods. Use it because of convention, and that it looks

Objective-C tab settings and whitespace style

亡梦爱人 提交于 2019-12-04 17:15:07
问题 Apple's Objective-C documentation, references, and generated code seem to be totally inconsistent with their coding style. I can not determine the "preferred" style (if one exists) for Objective-C and Cocoa source code. Here's what I've ran into so far. Tab settings Xcode's default setting is set to tabs. However, generated projects are always created with 4 spaces regardless of your tab settings. Worse, some generated code has stray tabs hanging around. Downloaded code examples seem to vary

Indenting with white spaces, tabs, and how many spaces or the tab width [closed]

会有一股神秘感。 提交于 2019-12-04 17:13:33
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 years ago . I know that this is more of a coding style, instead of a one right way of doing things. But, I'm a bit frustrated if I came across different indenting formats. But, I would like to hear the reasons by various people on these issues: Do you use spaces or tabs? Tabs with spaces? Any