7
голосов
9ответов
4379 просмотров

Guideline: while vs for

Disclaimer: I tried to search for similar question, however this returned about every C++ question... Also I would be grateful to anyone that could suggest a better title. There are two eminent loop structure in C++: while and for. I purposefully ignore the do ... while construct, it is kind o...

0
голосов
3ответов
773 просмотров

How to automatically convert underscore_identifiers into CamelCaseIdentifiers?

I have large C++ code base. It is quite inconsistent where uses underscore_identifiers and where CamelCaseIdentifiers, but is consistent within groups of files. Think about it as a smaller library merged into bigger one. I want to standardize it within this project to Google C++ Style Guide. How...

1
голосов
8ответов
602 просмотров

Better way to write this Java code?

public void handleParsedCommand(String[] commandArr) { if(commandArr[0].equalsIgnoreCase("message")) { int target = Integer.parseInt(commandArr[1]); String message = commandArr[2]; MachatServer.sendMessage(target, this.conId, message); } else if(commandArr[0].equal...

0
голосов
7ответов
13027 просмотров

PHP Line Indentation

I'm curious to know, how many spaces of indentation do you prefer in PHP code? function one() { $one; function space() { $space; } } function two() { $two; function spaces() { $spaces; } } function three() { $three; function spaces() { $spaces; } } function...

6
голосов
3ответов
41250 просмотров

HTML toggle buttons

I need to represent a toggle button in HTML. My intention is to do it with a normal input submit button and styling. Any recommendations on how to style a toggle button that is understandable and works more or less in all browsers?

1
голосов
3ответов
543 просмотров

How to make this ruby method less ugly (nesting)

I have a helper method that creates navigation links for some controllers. def gen_associations(controllers) content_for :leftnav do sorted_controllers = controllers.sort returning String.new do |content| content << content_tag(:h3, "Associations") << ...

1
голосов
6ответов
198 просмотров

Proper notation using doubles

It is more stylistically acceptable in java to write constants in double operations with or without ".0" ? As in, double var= 200.0; double d= var/250.0; double h= 1.0 - d; vs. double var= 200; double d= var/250; double h= 1 - d; Thanks

12
голосов
6ответов
5802 просмотров

Should useless type qualifiers on return types be used, for clarity?

Our static analysis tool complains about a "useless type qualifier on return type" when we have prototypes in header files such as: const int foo(); We defined it this way because the function is returning a constant that will never change, thinking that the API seemed clearer with const in pl...

4
голосов
10ответов
3801 просмотров

Java operator overloading

Not using operators makes my code obscure. (aNumber / aNother) * count is better than aNumber.divideBy(aNother).times(count) After 6 months of not writing a single comment I had to write a comment to the simple operation above. Usually I refactor until I don't need comment. And this made me...

21
голосов
13ответов
4562 просмотров

How to deal with seniors' bad coding style/practices?

I am new to work but the company I work in hires a lot of non-comp-science people who are smart enough to get the work done (complex) but lack the style and practices that should help other people read their code. For example they adopt C++ but still use C-like 3 page functions which drives new ...

1
голосов
2ответов
467 просмотров

Winform style issue: Windows classics style?

In one application I'm suddenly getting a style that looks like windows classics. It looks good in the Visual Studio designer (left on the image) but when I run the application it looks like windows classics style (right on the image) and I can't find it. I tried to create a new clean window an...

36
голосов
11ответов
41864 просмотров

Declaring a looooong single line string in C#

Is there a decent way to declare a long single line string in C#, such that it isn't impossible to declare and/or view the string in an editor? The options I'm aware of are: 1: Let it run. This is bad because because your string trails way off to the right of the screen, making a developer rea...

2
голосов
2ответов
375 просмотров

Coding style: function and procedures coding standard

Ch 7.6 of Code Complete 2 is confusing me, I've attached some sample code (in php) mind telling me which style is the best? or suggest something better? thanks Style 1 public function register($user, $pass) { if($this->model->isRegistered($user) { return false; } else if($this->t...

32
голосов
10ответов
4811 просмотров

Does functional programming mandate new naming conventions?

I recently started studying functional programming using Haskell and came upon this article on the official Haskell wiki: How to read Haskell. The article claims that short variable names such as x, xs, and f are fitting for Haskell code, because of conciseness and abstraction. In essence, it cl...

68
голосов
9ответов
19726 просмотров

Why does StyleCop recommend prefixing method or property calls with "this"?

I have been trying to follow StyleCop's guidelines on a project, to see if the resulting code was better in the end. Most rules are reasonable or a matter of opinion on coding standard, but there is one rule which puzzles me, because I haven't seen anyone else recommend it, and because I don't se...

7
голосов
14ответов
1866 просмотров

What the ugliest API for a relatively well known library that you have seen, and why and how could it be improved?

I have been looking at the differences between Lucene 2.9 particular the redone tokenstream API and it just occurs to me its particularly ugly compared to the old just return a new or repopulate the given with values if your reusing said Token. I have not done any profiling but it seems using a...

3
голосов
4ответов
261 просмотров

Should you import all classes you use in Python?

Python's lack of static typing makes it possible to use and rely on classes without importing them. Should you import them anyway? Does it matter? Example someclass.py class SomeClass: def __init__(self, some_value): self.some_value = some_value someclient.py class SomeClient: ...

18
голосов
7ответов
22359 просмотров

Default int type: Signed or Unsigned?

When programming in a C-like language should one's "default" integer type be int or uint/unsigned int? By default, I mean when you don't need negative numbers but either one should be easily big enough for the data you're holding. I can think of good arguments for both: signed: Better-behaved...

3
голосов
3ответов
257 просмотров

Is there a cleaner way to chain empty list checks in Python?

I have a fairly complex object (deserialized json, so I don't have too much control over it) that I need to check for the existence of and iterate over a fairly deep elements, so right now I have something like this: if a.get("key") and a["key"][0] and a["key"][0][0] : for b in a["key"][0][0...

5
голосов
1ответов
3781 просмотров

How to output JTextPane styled contents to HTML, including custom style?

I currently use a JTextPane to allow users to add/edit text. It allows bold/italic/underline (and I plan to allow links in the future). It also allows users to drop buttons in, which are inserted as custom styles. The panel looks like: <> I would like to be able to save/load content as HTML...

25
голосов
4ответов
18239 просмотров

Capitalization convention for JavaScript objects

I know this question has no answer, but I'm curious to know what other people think. In a language like Java, it's a convention to begin classes with capital letters, and objects with lowercase letters. But what about JavaScript, where everything is an object? I've seen some people suggest capi...

11
голосов
4ответов
3179 просмотров

What should the standard be for ReSTful URLS?

Since I can't find a chuffing job, I've been reading up on ReST and creating web services. The way I've interpreted it, the future is all about creating a web service for all your data before you build the web app. Which seems like a good idea. However, there seems to be a lot of contradictory t...

1
голосов
2ответов
169 просмотров

Cleanup Symfonys View Templates

I'm evaluating the PHP webframework: Symfony for a project. Everything is quite well organized so far, except for the view templates which suffer from an unreadable/error prone mix of html and php (I was trying to adapt the views to use clean urls and that just turned out to be an exercise in "sp...

8
голосов
2ответов
1316 просмотров

PHP class def: Individual accessors/mutators or __set() with switch()?

When defining a PHP class, which is preferred/best practice? Are there any key differences I'm overlooking? It seems like it could be more clean, concise, and convenient to write a __set() magic method and put a switch() construct in it with cases for all the private members to which I want to a...

21
голосов
3ответов
9228 просмотров

StyleCop vs ReSharper and general coding-style questions

Just found StyleCop, looks like something worth using for my projects. Then I found out you could use it with ReSharper (a tool I've also never used). So I downloaded ReSharper, as well as StyleCop for ReSharper. I'm just a bit confused about it, though: With just StyleCop installed (no ReSharp...

4
голосов
6ответов
179 просмотров

How to deal with changing feature and product names in source code?

What is a good strategy for dealing with changing product and feature names in source code. Here's the situation I find myself in over and over again (most of you can relate?)... Product name starts off as "DaBomb" Major features are "Exploder", "Lantern" and "Flag". Time passes, and the Featu...

3
голосов
6ответов
741 просмотров

3-Tiered Web Architecture: Are Layers on Separate Machines Beneficial?

A client I'm working for has a standard in which they require the data layer of new applications to be wrapped into a web service, and placed a machine separate from where the business/presentation layer will be hosted. Could someone tell me what the benefits of doing this are? It seems to me t...

2
голосов
2ответов
447 просмотров

"dangling" local blocks in scala

In scala it is possible to define a local block in a function. The local block evaluates to the last statements, for example, val x = {val x =1;x+1} Here x==2, the inner val x is local to that block. However those local blocks can cause sneaky bugs when writing anonymous classes. For example ...

3
голосов
5ответов
4231 просмотров

How to write unit tests in spec form?

I have difficulty in many situations to come up with a good unit test names for classes and methods. Typically, I try to follow the form: public class TestContext { [Fact] public void WhenThis_DoThat() { } } Some put words Given, When, and Then on the parts to be explicit. I ...

1
голосов
1ответов
399 просмотров

Font properties

I have a text file with the following info in it, on a single line: -16777216 Arial 7.8 Bold (-16777216 is the color of the text in ARGB format).. How would I be able to set this text as the font properties for a label at runtime? I have googled this but couldn't find anything related specif...