A coding style is a set of conventions and practices used in software, such as naming classes, variables, and files.

learn more… | top users | synonyms

1
vote
0answers
9 views

Trying to get better at Ruby and programming in general- here's a simple TopCoder question in Ruby

I want to get general feedback and feedback about if I can make this more Ruby-like, if there are any obvious inefficiencies, and if I need to organize my class differently. The topcoder question is ...
0
votes
0answers
7 views

Is there a better way to count seconds in python

def stopWatchSeconds(secondCnt) : """ counts second for secondCnt seconds """ # is there a better way to do this? startTime = time.clock() ellapsed = 0 for x in range(0, ...
5
votes
1answer
59 views

Recommended Naming for function that tests and mutates

I am a huge proponent of self-documenting code (when at all possible). I prefer to have code be self evident by the very nature of the names of the variables, methods, etc.. For instance: if ...
-1
votes
0answers
33 views

Checklist for coding MVVM web application [closed]

We are a small team working on a web application using MVVM design pattern using technologies like .NET, Knockout and HTML. I am trying to come up with a code review process and as a first step trying ...
3
votes
2answers
43 views

Default value or conditional?

Which of the following two is preferred: var somevar = valueA; if(condition) { somevar = valueB; } or: var somevar; if(condition) { somevar = valueB; } else { somevar = valueA; } ? ...
2
votes
2answers
42 views

Global variables in python, bottle microframework

I'm sort of at a loss for what to do with webapps and whether what I'm doing is actually allowed or not. Here is a sample of the type of thing i'm doing at the moment. I need a list that is accessible ...
1
vote
2answers
86 views

Email report generation from database

I have written a small batch job which will collect data from db and send mail to user. Can you please do a review of the code with design prinicples in mind and also with best practices for Db and ...
-1
votes
1answer
54 views

Java Question for An Absolute Beginner [closed]

This is for a beginning Java course that poses the problem: Write a class named Employee that has the following fields: name. The name field references a String object that holds the employee's ...
2
votes
1answer
71 views

Can I make a regex array to iterate through in C++?

I have to check a string to various regular expressions in C++. Up to now, I've done this using something similar to this: regex regex_a (".."); string rewrite_a = "($1/$2)"; regex regex_b (".."); ...
2
votes
0answers
124 views

Best practice and/or cleaning binary/decimal/octal/hex converter (now for floating-point values)

This new code comes from my original converter (without floating-point support): Cleaner and/or more practical code for decimal/binary/hex converter I've had some trouble implementing floating-point ...
1
vote
1answer
58 views

Create palindrome by rearranging letters of a word

Inspired by a recent question that caught my interest, I wrote a function in Python 3.3 to rearrange the letters of a given string to create a (any!) palindrome: Count the occurrences of each letter ...
2
votes
1answer
32 views

Scheme/Racket: idiomatic infix math evaluator

Inspired by xkcd and a couple of praising blog posts, I decided to try out Lisp. It seemed that the best-supported dialect was Racket, itself a variant of Scheme, so I went with that and wrote an ...
1
vote
1answer
47 views

Recursive Determinant

The following code I devised to compute a determinant: module MatrixOps where determinant :: (Num a, Fractional a) => [[a]] -> a determinant [[x]] = x determinant mat = sum [s*x*(determinant ...
2
votes
3answers
143 views

Cleaner and/or more practical code for decimal/binary/hex converter

I've finally finished my converter and have determined that it works, but I'm trying to make it cleaner and/or more practical (primarily with the switch statements). I could probably put more things ...
0
votes
1answer
71 views

I've finally found a satisfactory way to create classes on JavaScript. Are there any cons to it?

Depending on external OO libraries is really bad, using prototypes/new has some limitations, using only hashes has others. Dealing with classes was always a pain in JavaScript and it didn't help that ...
1
vote
0answers
56 views

Vaadin web application

I am creating a web application for an enterprise and I would like to improve my way of coding, know what I do wrong and what I do well. I'll leave the main class' code here: package com.puntobile; ...
3
votes
1answer
280 views

Which is better: the short, clever way, or the long, ctrl+c way?

The code below is equivalent. I can see pros and cons for both versions. Which one is better? Short version: character.on("key",function(key){ var action = ({ ...
1
vote
1answer
100 views

Playing Card Class - is this right?

The Art and Science of Java, a course book that uses the ACM library has an exercise that reads like this. Implement a new class called Card that includes the following entries: • Named ...
1
vote
1answer
112 views

Code review for an abstract repository implementation

I have a repository abstract class that encapsulates pretty much all of the CRUD functionality: public abstract class DataRepository<T> : IRepository<T> where T : class { public ...
1
vote
1answer
129 views

Which code is better? And why?

I found two ways of writing the same program (one that only uses local variables, but no methods other than the main one) and other that uses one instance variable that is used in two methods. This ...
2
votes
2answers
113 views

How can I improve this coin flipping code?

I am doing exercises for the Art and Science of Java textbook. I had an exercise that required me to program the simulation of flipping a coin until 3 consecutive "Heads" result appeared. I did it, ...
2
votes
1answer
97 views

What steps to turn python code into python zen code

My python code is ugly and I'm having difficulty improving it. What kind of steps could be done here to make it. This is an example function that comes from time to time and I can't seem to have a ...
0
votes
1answer
55 views

How to make proper code out of this function

public function getStuff($brand) { $web=FALSE; if($this->getWebcorners()): foreach ($this->getWebcorners() as $webcorner): ...
4
votes
1answer
151 views

How do I make this code unit-testable?

I have a functionality that imports data into a database, based on an Excel workbook and some meta data (both user-supplied). The functionality implements interface IFunctionality which essentially ...
0
votes
0answers
73 views

Hanoi Towers - need help with the code

I made an algorithm solving Hanoi Tower puzzles, for n disks and m pegs. It uses lists as pegs, each list's element contains disks array - {0, 0, 0} means the peg is empty, {1, 2, 0} means the peg ...
1
vote
2answers
65 views

Looking for Python code review of database abstraction class

I'd be very thankful if some Python masters would take a look over the following class and review the code. There is no bug(not as far as I know anyway), the code is working as intended. But, since ...
0
votes
0answers
24 views

First time writing MIPS code and was hoping somebody could look at it and help me clean it up (Prime Factors)

The goal of this was to be able to enter any number and print out the prime factors of that number. Are there any shorter ways of writing this code? I'm not very familiar with low-level syntax and was ...
2
votes
2answers
247 views

Haskell markov text generator

I'm new to Haskell, and here is my first not-totally-trivial program. It's the first program I tend to write in any language -- a Markov text generator. I'm wondering what I can change to make it more ...
1
vote
0answers
51 views

Reviewing javascript and tidying up?

This is a follow up to this question my code has evolved since so I'm reposting my question, What is the best way to tidy this up? how can this be refined? I am finding it's thrasing the layout quite ...
2
votes
1answer
86 views

A complex string splitter- How do I make this working code better?

I have the below program class Program { static void Main(string[] args) { List<Assembly> failedAssemblies = LoadAssembly(); string batchFile = ...
1
vote
2answers
135 views

How can I refactor this code in order to not repeat code?

I have this code: private eFileStatus CheckConfigSettings() { mFileStatus = mXMLHelper.CheckElement(eElementName.StartLanguage.ToString(), out mContent); if (eFileStatus.OK != ...
7
votes
2answers
232 views

What could I have done better?

This is my first real program, though it has gone through a few major revisions. Anyhow, I am sure that there is a lot I could have done better, cleaner or safer. Can anyone see anything I really ...
3
votes
1answer
98 views

The eternal dilemma: bar.foo() or foo(bar)?

I was using foo(bar) as it's adopted for functional programming. console.log( join( map(function(row){ return row.join(" "); }, tablify( ...
1
vote
3answers
93 views

Could I possibly shorten / clean this up

I'm new to Python, and I'm wondering how I could possibly shorten / clean this up? def userAnswer(letters): print("Can you make a word from these letters? "+str(letters)+" :") x = ...
4
votes
3answers
137 views

Code Tidying up?

What is the best way to tidy up JavaScript code I have written. It seems very long winded, any suggestions to shorten it? note: I'm running it on Wordpress which runs jQuery in nonconflict mode. ...
-1
votes
1answer
94 views

How to apply Sieve of Eratosthenes test into my code [closed]

I have this code that tests prime numbers and I'm trying to make it fast as possible. I know a way but I just can't find how to execute it in to my code. Does any one know how to input in to the code ...
2
votes
1answer
95 views

Simple and efficient code for finding factors and prime factorization?

I've modified this program many times, but I want to know if this is a good way to perform this task. My first algorithm for finding the factors of a number was pretty slow and horrible (started at ...
3
votes
2answers
128 views

Palindrome test in Haskell

I am new to Haskell and, coming from a OO/procedural programming background, I want to make sure my code follows the functional way of doing things. I built this short module to test if a given string ...
1
vote
1answer
91 views

General feedback for my GCD/LCM x86 Intel NASM assembly program

I've already created a similar program in C++ first, and then I decided to try to write it in x86 assembly language (the type of assembly I was taught in college). I've already completed the C++ ...
1
vote
3answers
88 views

Improving Javascript code of a failed test

I just failed in a JavaScript test and I would really appreciate some comments of how I can improve so I can keep learning. The test was about making a form interactive, where the code should do ...
4
votes
2answers
68 views

Improving Code pointers

I'm new to jQuery and I've been messing about with this code, It works but I want to learn how to shorten the code by the eliminating unnecessary repeated code. Below is a link to jsFiddle ...
1
vote
0answers
41 views

Hardware resource Open/Close methods

So I'm making a program that is a serial port wedge. In other words I want it to listen to a serial port. If data comes in, wait a given amount of time, then play a sound and finally send the data ...
3
votes
2answers
86 views

improve the design of class “accuracy” in Python

I am learning about the class and methods in Python. The class Accuracy is a class of several (13 in total) statistic values between a reference polygon and one or more segmented polygons based on ...
3
votes
2answers
116 views

How can this this URL Checker be made cleaner?

I have a table full of URLs, some of which will occasionally become invalid. As part of a system I'm writing to go through the links periodically, and test if they are valid (or redirect to valid ...
4
votes
4answers
206 views

Command line Contact Management

Can you please review the following code and give any suggestions for improvment? Class ContactList.java import java.io.*; import java.util.*; public class ContactList { public static void ...
1
vote
4answers
144 views

Double conditional : Cleaner way to write a set of conditionals

Is there a cleaner way to write: def b_fname if mdes_version_is_after?(3.0) result = c_fname else result = response_for("#{birth_baby_name_prefix}.BABY_FNAME") end if ...
5
votes
1answer
98 views

CSS Good Practice on a JavaScript Plugin

I've realized a jQuery Plugin recently and made a basic default CSS for it. As I'm mainly a server-side guy, I'm not too familiar with CSS and would like to have insight about what could be improved. ...
3
votes
2answers
189 views

jQuery Object Oriented Plugin

Update: Great answers up to now, but I would still love to have a bit of review about possibility of variable caching and the filter I'm using for rows and page sets! After seeing a lot of ...
1
vote
3answers
151 views

Possible improvements for this small C program?

I'm learning C and today I wrote a program that displays info about my hardware on ubuntu. #include <stdio.h> #include <stdlib.h> int main() { char ch, file_name[25] = ...
2
votes
1answer
35 views

Multi jQuery Sliders, Help me write this in better code

I have three sliders with different min, max values, everything is working fine from following the tutorials on the jQuery UI website. $("#yield").slider({ range: true, min: 15.2, max: ...

1 2 3 4