coding-style

What is the best way to use whitespace while programming? [closed]

末鹿安然 提交于 2019-12-03 13:11:31
I'm fairly new to programming and from learning I have seen different ways of formatting code, comments, etc; and have been recommended on different techniques. I mostly program in C#, C++, and Java so I want to know what is the the best way to layout code so that if other people where to go through it, they would be impressed by how simple and easy to understand it is. The best rule to follow is: (and probably the only rule everyone will agree on) Be consistent! Pick one style and stick with it. Always put your braces in the same place. Use similar naming conventions. Don't mix tabs and

Call member function on each element in a container

ⅰ亾dé卋堺 提交于 2019-12-03 13:10:13
This question is a matter of style, since you can always write a for loop or something similar; however, is there a less obtrusive STL or BOOST equivalent to writing: for (container<type>::iterator iter = cointainer.begin(); iter != cointainer.end(); iter++) iter->func(); ? Something like (imagined) this: call_for_each(container.begin(), container.end(), &Type::func); I think it would be 1) less typing, 2) easier to read, 3) less changes if you decided to change base type/container type. EDIT: Thanks for your help, now, what if I wanted to pass some arguments to the member function? #include

Standard for programming 'beautiful' code in Java? [closed]

安稳与你 提交于 2019-12-03 12:40:48
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 8 years ago . I'm reading some books about coding standard in Java. I always loved beautiful and clean code. But there are some things that bother

Fastest/Cleanest way to load a text file in memory

﹥>﹥吖頭↗ 提交于 2019-12-03 12:38:18
I know similar questions have been asked before, but I couldn't find one that answers my exact question. I need a way to read a file as a String with the least code and as simple and as optimal as possible. I'm not looking for: final BufferedReader br = new BufferedReader(new FileReader(file)); String line = null; while ((line = br.readLine()) != null) { // logic } And I know I can write my own helper class that does this. I'm looking for something more along the lines of: final String wholeFileAsStr = Something.load(file); Where Something.load() is super optimized and buffers the file

Immutable Collections Actionscript 3

穿精又带淫゛_ 提交于 2019-12-03 12:30:04
问题 I've been trying lately to implement some clean coding practices in AS3. One of these has been to not give away references to Arrays from a containing object. The point being that I control addition and removal from one Class and all other users of the Array receive read only version. At the moment that read only version is a ArrayIterator class I wrote, which implements a typical Iterator interface (hasNext, getNext). It also extends Proxy so it can be used in for each loops just as a Array

objective c coding guidelines

安稳与你 提交于 2019-12-03 12:29:58
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... rcw3 I would start with these: Apple's Coding Guidelines for Cocoa Google's Objective-C Style Guide Take a look at Objective-C Beginner's Guide . 来源: https://stackoverflow.com/questions/2543090/objective-c-coding-guidelines

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

烂漫一生 提交于 2019-12-03 12:19:05
Closed. This question is off-topic. It is not currently accepting answers. Learn more . Want to improve this question? Update the question so it's on-topic for Stack Overflow. I mean to name ids, names, values, etc? 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 Class and ID in CSS Here are a few good paragraphs that summarize what the author is trying to get at: A designer

How does the verbosity of identifiers affect the performance of a programmer?

断了今生、忘了曾经 提交于 2019-12-03 12:16:00
I always wondered: Are there any hard facts which would indicate that either shorter or longer identifiers are better? Example: clrscr() opposed to ClearScreen() Short identifiers should be faster to read because there are fewer characters but longer identifiers often better resemble natural language and therefore also should be faster to read. Are there other aspects which suggest either a short or a verbose style? EDIT: Just to clarify: I didn't ask: "What would you do in this case?". I asked for reasons to prefer one over the other, i.e. this is not a poll question. Please , if you can, add

Modifying the innerHTML of a <style> element in IE8

白昼怎懂夜的黑 提交于 2019-12-03 11:51:48
I am creating a style element and I need to put some CSS into it. The below code works in Chrome, Safari and FF, but fails in IE8: var styleElement = document.createElement("style"); styleElement.type = "text/css"; styleElement.innerHTML = "body{background:red}"; document.head.appendChild(styleElement); In IE8, the code fails when it comes to the innerHTML part. I've tried doing: var inner = document.createTextNode("body{background:red}"); styleElement.appendChild(inner); But this also fails with "Unexpected call to method or property access." I'm looking for a workaround or fix. Use

Code style with Annotations [closed]

强颜欢笑 提交于 2019-12-03 11:32:48
I can't make up my mind between @MyAnnotation(param1="paramval") public void foo(){} and @MyAnnotation(param1="paramval") public void foo(){} Is there a best-practice emerging? We use the first case. Annotations don't fit on one line in some cases . What happens in that annotations keep adding up in our project, responsibility after responsibility. Having annotations for really different concerns on the same line becomes messy. Also, some annotation can become really big, and be multi-liners on their own (I think of Hibernate mapping redefinition in a subclass). I'd say there is no hard fast