Programming style is a set of rules or guidelines used when writing the source code for a computer program.

learn more… | top users | synonyms

2
votes
3answers
212 views

Coding style preference if (aPtr), if (aPtr != NULL), or if (NULL != aPtr) [closed]

I understand that as far as the compiler is concerned, the following lines are equivalent. if (aPtr) {...} if (aPtr != NULL) {...} if (NULL != aPtr) {...} ...
2
votes
2answers
94 views

How to format embedded if statements in JavaScript

What would be the best way to format this code? It looks a bit messy to me in regards to indentation etc. ...
10
votes
2answers
453 views

Is indentation of #if & #endif directives an important readability convention?

I'm sharing C# code with a fellow programmer who is more use to writing C++. He uses #if and #endif directives (which I do not ...
11
votes
3answers
189 views

Java 8 Effective Use of Multiple Streams

I am experimenting with streams and lambdas in Java 8. This is my first serious foray using functional programming concepts; I'd like a critique on this code. This code finds the Cartesian product of ...
4
votes
2answers
84 views

Better PHP Ajax Request Processing Structure

I have a server side PHP file which processes Ajax requests from the client browser. Some requests are only valid if they originate from an Administrator in the application, others are only valid if ...
4
votes
1answer
71 views

Is this the Clojure way?

Is there a way to write this better or more Clojure way? Especially the last part with with-open and the let. Should I put the ...
3
votes
1answer
164 views

Simple framework for Google Code Jam problems

My main concern is code style. Could you review this? ...
2
votes
1answer
52 views

Prototype OO-style of my THREE.JS application

For several months I'm working with JavaScript and THREE.JS library. Firstly I dislike the prototype-based programming because I have to work a lot of with ...
6
votes
1answer
188 views

Implementation of binary heap in C++

Things I can think of include integer overflow, if the input type is int, etc. But other than that, what do you think is wrong with this code, design-wise, style-wise, and also in terms of other ...
3
votes
1answer
74 views

Class naming conventions

I have the following scenario: The (web-) application is built with Java/Spring. I have several REST-endpoints which deliver data prepared to be consumed by a frontend by ...
10
votes
1answer
112 views

Finding the next higher digital permutation of a number

This is my solution for CodeEval challenge 44. The function followingInteger takes a number in its decimal representation and returns the next higher permutation ...
3
votes
1answer
74 views

Is it a good style to run external commands in Python?

I have lots of external shell commands to run. So I gave every command a name and then run it. ...
3
votes
1answer
56 views

cleaner python — refactoring to reduce noise? (twirling cursor)

Questions: (1) Is the cost of calling subroutines in Python cheap enough to support refactoring, i.e. pulling out flash() as its own subroutine, ...
4
votes
2answers
104 views

Shorten code that gathers files from directories

I have the following method in Ruby that appears to be just one line too long according to Ruby style guides. (Specifically: Rubocop tells me that my method has too many lines.) Granted, I'm only one ...
40
votes
11answers
8k views

Nesting versus GOTO: which is better to avoid?

In Java they're not really known as GOTO statements and are rather referred to as Branching Statements, but I find that the former term is a bit more indicative of ...
7
votes
3answers
103 views

Removing unnecessary floats, height, widths

I have coded a webpage and it looks exactly how I want, but I think there could be improvements, possible as unnecessary floats, etc... Could anybody please review my CSS code? Its not difficult or ...
5
votes
1answer
55 views

Better way to write this branch with an exceptional retry in an embedded C environment?

A while back I wrote the following code (target is embedded C code on an 8 bit atmel device): ...
7
votes
1answer
165 views

Iterating string characters and passing them to a BIOS API

Which style of printing strings from the SI registry in NASM is more correct? I'm learning assembly and x86 architecture, but I'm rather new in it, so I've prepared two styles (in NASM) of printing a ...
5
votes
1answer
136 views

Code with many “early returns (exits)” into the functional style

I have some Scala code that uses Internet to authorize a user. Therefore, it can throw Exceptions like IOException in the method. The original code was written in ...
7
votes
1answer
848 views

In-memory cache implementation

A few years ago I required a lightweight in-app-in-memory cache. Requirements: Time complexity O(1) for individual element read/write access Space complexity ...
2
votes
1answer
104 views

Naming convention in my C++ library

I am implementing a library in C/C++11 and I have chosen to follow Google C++ Style Guide as I also use this Style Guide in my code. As such all classes and types (including ...
1
vote
3answers
103 views

Three ways to add pronoun method/property to gendered class in Python

Say you have a Python class for something that has an optional gender field. You'd like a helper property/method to get the appropriate pronoun for an instance. You'd also like to be able to get the ...
2
votes
1answer
75 views

Helping my coding style with a java text server

I consider myself a beginner at writing in Java. I have never had a programming class, nor had my code reviewed. I have come to Code Review for some pointers. (Tips that is, not data references.). I ...
0
votes
1answer
103 views

Is such style good for using unsafe features in C#? [closed]

Is such style good for using unsafe features in C#? Or, why is it bad to develop such code? ...
4
votes
3answers
107 views

Improving F# conditional assignment with match expression

In my code I declared a dictionary to store various counters let counters = Dictionary<Type, int>() Later, I need to generate several labels using these ...
4
votes
4answers
80 views

Help in deciding how to represent a long regular expression

I wrote a simple Polynomial class: ...
1
vote
4answers
168 views

Polishing and re-designing C code to C++ OOP principles [closed]

I would like to ask a question that many of you may find naive, so excuse me for that. I am coding a program that so far it has been built step-by-step while reading something like a manual, so it is ...
2
votes
1answer
179 views

Python Palindrome Generator

I've just written a palindrome generator and would like to know what you think about it. Especially: code style Is it possible to get the same result without making a special case for 1-digit ...
0
votes
0answers
87 views

Optimizing my Quadratic Sieve, with advice on style?

I'm still new to Haskell, and I'd like others' opinions on optimizing my basic quadratic sieve, in addition to feedback on the code's clarity and functional style. The ...
6
votes
1answer
207 views

Elegant way of writing JSON parsing function using the Jansson library

I'm making a server in C that needs to parse JSON that follows oBIX protocol and I'm using the Jansson library for this. I've been programming in high level languages such as Java and C# for my entire ...
2
votes
1answer
238 views

Is this an elegant/accurate simulation of the Monty Hall problem?

I'm trying to simulate the Monty Hall problem, to statistically determine if there is any benefit to changing my choice after a door containing a goat is open (testing this guy's Monty Hall theory on ...
1
vote
1answer
86 views

Munkres algorithm in Python: calculating maximum profit

I'm using Munkres library from https://github.com/bmc/munkres/ to calculate maximum profit (reversed problem). What do you think about this coding style? ...
4
votes
1answer
204 views

Is this kitchen timer code pythonic?

I've been doing bits and bobs with Python for a few years, but I've never took the time to get feedback on what's pythonic and what's not. In the interest of collaborating more with Python ...
1
vote
1answer
28 views

CSS Styling: Should I specify the element type?

Which of the following is better code: div#style1{ } or #style1{ } Also, should the element type be specified for ...
3
votes
2answers
136 views

K&R 1-20 Suggestions for Style and a better C Paradigm

I'm learning C with K&R 2nd Ed. I just completed ex 1-20 (which is the detab program). I was hoping to get some feedback on my work. I want to make sure that ...
5
votes
2answers
288 views

Search Android contacts more efficiently?

there is better way to do that? like more efficient? ineed to do this code, but my moderator tell me to do this with more efficient way thx for help: onCreate:(starters...) ...
3
votes
2answers
63 views

Style and Suggestions for K&R2 1-18

I just completed K&R (2nd Ed.) ex 1-18. I'm fairly new to C, but have had experience in other languages (Perl, C++, Java, Common Lisp, PHP, etc) and really want to learn the C idiom as opposed to ...
3
votes
2answers
157 views

Converting Java int based amount to Coin metrics - better implementation or style?

I was tasked with writing a method which would take in an int (for amount in coins) and then convert the coins, accordingly, by counting how many quarters, dimes, nickels, and pennies were located in ...
2
votes
1answer
91 views

Streamlining repetitive class definitions in python with a class_factory() function

I forked this repo to be more concise. The code is here. I'll paste it below since that seems to be the style. I removed the class definitions at the bottom that I didn't change -- the edit I'm ...
2
votes
1answer
118 views

How to make code more pythonic?

Good day! I am writing my first programs on Python and want to be sure my code is good and not too C++ed. Consider the problem ...
1
vote
5answers
419 views

Trimming a string

Function: Trim Returns a new string after removing any white-space characters from the beginning and end of the argument. ...
5
votes
2answers
404 views

In-Place Quicksort in Python

Code is below. I'd like to know if this is a solid/efficient implementation of the in-place quicksort algorithm and if my Python style is good (I know there are no comments for now). Code is also on ...
3
votes
2answers
166 views

Project Euler #1 - Multiples of 3 and 5

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. ...
5
votes
2answers
323 views

Abstraction for an IO device

I have a C++ class which acts as an abstraction for an IO device which is controlled through file descriptors. As I am very new to C++, I would be glad if you can give me devastating feedback on ...
6
votes
2answers
271 views

Style, simplification and modularization for unit converter

Here is an exercise I completed today from Bjarne Stroustrup's Programming Principles and Practice in C++ book, any tips about coding style, simplification, or perhaps modularization by means of using ...
0
votes
1answer
54 views

javascript: data and vtables vs. objects and methods

I present a bunch of grids of data to the user, and want to sum certain columns in some of the grids. ...
2
votes
1answer
155 views

What is the best practice for working with a project as nested modules?

I come from the world of Python, so I'm used to every file representing their own enclosed module, never polluting the global environment. Up until now (I've worked with Ruby for a week) I've created ...
9
votes
4answers
584 views

Polynomial program - is my style/design completely off?

This is my first post here. I'm a complete beginner in C++ (started yesterday). With a couple of hours of work I managed to get my first console application to work (aside from the obligatory "Hello, ...
3
votes
2answers
63 views

Default value or conditional? [closed]

Which of the following two is preferred: var somevar = valueA; if(condition) { somevar = valueB; } or: ...