Readability is the quality of written code that makes it easy to read and understand.

learn more… | top users | synonyms

0
votes
0answers
14 views

Could this ROM reader be faster and/or smaller?

I've been practicing arduino programming for a few weeks now having become confident in reading and writing to pins so I decided to take it a step further and do a serious project that does both, so ...
2
votes
2answers
7 views

How to make the end of loop more readable in Ruby

There are some blocks in my code. To make it easier to read, I often append comment after the end such as end # end upto end # fileopen Because sometimes the indentation still not easy for ...
2
votes
1answer
109 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
0answers
70 views

Template parameter pack of parameter packs

This is for C++11, but d-developers and others are welcome to answer in their language. The question is how to best extend typname...T1, typename...T2 to an arbitrary amount of packs. The first ...
1
vote
0answers
48 views

Improving readability of Boolean adder generator?

Today I've noticed that the source code for a Boolean adder is very repetitive, so I wrote a Python script to generate the C source code. The script generates an adder of varying size depending on ...
2
votes
3answers
58 views

Function for encoding strings in-place

I recently wrote a function that replaces every white space with '%20', just for fun (and sharping my coding skills). The input string is terminated with extra white spaces, with the length that the ...
1
vote
2answers
89 views

Readable Ruby Gem

So the main purpose of Ruby is to be readable. I hope I did a good job with this gem I made. If there's any kind of suggestion of how to make this better, then please tell me. class Trigger # event ...
2
votes
1answer
96 views

Method names for encapsulated unit testing logic. Which convention is better?

I have some C# unit tests which each basically perform the same steps but supply different arguments to the unit under test. I wanted to encapsulate the logic inside some "helper methods" but found ...
0
votes
1answer
55 views

Review of String to Long bijection class - focus on readability/maintainabiliy

I wrote the following interface and class to bijectively map a string to a long. I would like feedback on how to make the code more readable and maintainable. Interface: /** * Bijectively maps a ...
0
votes
0answers
19 views

Can someone review my Rational implementation?

The header file can be viewed here. #include <stdio.h> #include <stdbool.h> #include <math.h> // searches default library classpaths #include "Rational.h" // searchs my directory // ...
1
vote
1answer
30 views

Can someone review my Polynomial data structure?

The following is working but I just want to know if I can make it better in any way. The header file can be viewed here. #include <stdbool.h> #include <stdlib.h> #include "Polynomial.h" ...
4
votes
4answers
206 views

More Pythonic way to write this is_palindrome function?

from string import punctuation, ascii_lowercase def is_palindrome(string): """Return True if string is a palindrome, ignoring whitespaces and punctuation. """ new = "" for char in ...
3
votes
2answers
92 views

get rectangle count from given co-ordinates code review

Problem Description Write a program to find the maximum number of rectangles that can be formed both horizontal and vertical with the help of a given n number of coordinate(x,y) points. [x,y points ...
2
votes
1answer
51 views

Which of these two is better in terms of readability and function?

I have two different ways of populating a List with querying another List. They are: var list = _surveyList.Where(x => x.Date == selectedDate).Select(s => s.Joint).ToList(); And: var list = ...
3
votes
2answers
122 views

Is the use of Struct or Class personal preference?

I have a solution in which I instantiate a class with various types inside of it. I feel it is becoming to cumbersome to instantiate and then create variables for each of the types I want to access ...
1
vote
1answer
89 views

Is there a more readable version of this code? [closed]

Coworker put this in a pull request. I don't understand what exactly it's doing, I think it's the single-letter variable names, but is there something else that causes it to be slightly unreadable, or ...
2
votes
0answers
76 views

How can I improve my A* Pathfinding code? (again!)

Done this already, but looking to improve it even more. Nearly time to hand this project in, and I want it to be as close to perfect as possible. So, any issue (No matter how small) - Let me know. If ...
1
vote
1answer
378 views

Maximum Subarray Problem - Iterative O(n) algorithm

I implemented an iterative O(n) algorithm for solving the maximum sub-array problem. I would like a general review for it. Here the max_subarray is the main function and the ones which are static are ...
1
vote
0answers
126 views

Maximum Subarray Problem - Recursive O(n lg n) algorithm

I have implemented a recursive O(n lg n) algorithm for solving the maximum sub-array problem. I would like a general review for it. Here the max_subarray is the main function and the one which is ...
1
vote
3answers
97 views

Making my code better. I'm new(ish) to PHP

<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Add New Games</title> <meta name="viewport" ...
3
votes
1answer
72 views

URL percent encoding function

I wrote a custom URL encoding function and I'd like to run it past a few other experienced C developers. I have tested it on a few strings, and it has worked on all of them. This is to be run on ...
2
votes
1answer
152 views

How to separate code into smaller classes using SOLID principles

I have a console application that basically retrieves xml content, writes to the xml file and sends the file to sftp site. This may seem long post but I believe it is simple stuff that need advise on ...
2
votes
3answers
98 views

Should jQuery DOM Ready code be in the page with the HTML or separate JavaScript file?

I have an application with HTML, external JavaScript and a bit of jQuery on the page which is initializing specific stuff to that page. I try to keep most of the JavaScript in other files. However I'm ...
8
votes
3answers
250 views

Simple Java animation with Swing

Let me preface this by saying that I am new to this site as well as Java programming language. This site was recommended to my by a friend. That aside, let me thank you for taking the time to read ...
2
votes
1answer
99 views

Critique my JSON-optimizing Python script

Here's a Python script to optimize JSON documents: #!/usr/bin/python3 """jopo - Optimize JSON documents.""" from collections import defaultdict def optimize(data): """Optimize a JSON-like ...
1
vote
0answers
108 views

Writing the Word Equivalent of a Check (Cheque) Amount

I am looking for feedback on a solution to the following problem posed from a book that I'm working through (Java: How To Program 9th Edition) :- Continuing the discussion in Exercise 16.20, we ...
3
votes
1answer
90 views

Calculus program — Code review and suggestions

I have written a simple command line program in python3 that accepts a function (in the mathematical sense) from a user and then does various "calculus things" to it. I did it for my own purposes ...
0
votes
1answer
50 views

Ocaml Functional Programming Tree

I'm writing a function called unzip that turns: [(1,2);(3,4);(5,6)] to ([1;3;5],[2;4;6]) I've got a working implementation right here: let unzip (data:(int*int) list) : int list * int list = ...
2
votes
3answers
356 views

Number of Occurrences of Each Different Word in a Line of Text

I am looking for feedback on a solution to the following problem posed from a book that I'm working through (Java: How To Program 9th Edition) :- Write an application that reads a line of text ...
2
votes
1answer
178 views

Three Letter Strings From Five-Letter Words

I am looking for feedback on a solution to the following problem posed from a book that I'm working through (Java: How To Program 9th Edition) :- Write an application that reads a five-letter ...
0
votes
1answer
47 views

Arduino More maintainable code

Straight to the point: Can you give me pointers on how to make this code more maintainable? In the future, I want to add more more things to this, but first it should be easy to maintain/read. Should ...
0
votes
2answers
109 views

Refactor or keep this high-complexity method?

Is this acceptable for readability or would it be better to refactor it into smaller methods? Tips? Comments? Examples? def save_with_payment if valid? charge = Stripe::Charge.create(:amount ...
2
votes
3answers
92 views

Is this chained comparison readable?

Is this chained comparison easily readable and understandable? if result == problem.solution is not None: ... Or should it be changed to its possibly more obvious equivalent: if ...
5
votes
3answers
266 views

Binary Search in C - Optimization

I know that there is a function bsearch present in stdlib.h but still I want to implement this. This is my code for binary search. Any and all reviews are welcome. #include<stdio.h> ...
2
votes
1answer
83 views

Recursive Implementation of merge sort - Optimization

Information about my code: I am following this MIT OCW algorithms course. The first lecture described insertion sort and merge sort. I implemented merge sort in C. The algorithm is structured as a ...
3
votes
1answer
319 views

Implementation of insertion sort - optimization

Information about my code: I am following this MIT OCW algorithms course. The first lecture described insertion sort and merge sort. I implemented insertion sort in C. The algorithm is structured ...
6
votes
2answers
217 views

List<T> Any vs Count, which one is better for readability?

Resharper thinks I should change this while (dockPanel.Contents.Count() > 0) to the following: while (dockPanel.Contents.Any()) Without thinking twice about it, I switched to the any version ...
4
votes
1answer
154 views

Is this use of an array of function names and bracket-notation function calling a hacky/evil solution?

Background: I was making a chrome extension that injects movie ratings into theatres' showtimes pages. The problem I was duplicating a lot of code calling similar but just slightly different ...
2
votes
2answers
275 views

java Split Collection to two list depend on criteria

Let's say I have a List contains numbers: 1,2,3,4,5,6,7,8,9 and I would like to split this to two lists: - odd numbers - even numbers So I can do this two ways: Solution 1: Create two methods: ...
0
votes
0answers
23 views

Remapping Heading Angle to Coordinates to Move By

I wrote the following code to take the heading of an object, and determine which direction (x,y) it needs to move to be heading forward in a 2D plane. I have debugged the code and know that it ...
2
votes
1answer
126 views

Review a simple sprite sheet animation script

This is just a simple script for testing sprite sheet animations. I'm trying to improve my code style, so I'm curious about suggestions anyone might have about best practices or readability. ...
4
votes
1answer
172 views

Creating my own flow control statements in C++. Is that acceptable?

I always considered switch statement as somehow defective: works only on integral types and enumerations. isn't an readability improvement over traditional if/else chain. forget a break - you have a ...
3
votes
1answer
169 views

Why divide and conquer algorithm inefficient?

I was solving one of the problem in USACO 2007 Open Silver. The problem is as follows: Description Farmer John has taken his cows on a trip to the city! As the sun sets, the cows gaze at the city ...
2
votes
1answer
71 views

Making complex array initializations more readable

I have a function in the C++ program, which does simple computations and writes result to two arrays - result[53] and var1_new[53]. It contains two code blocks: The first one - double result[53]; ...
3
votes
1answer
109 views

Looking for advice on how to make my code better

I have to make project for school in C# which has to use database and web service. I have made program which starts web service and gets function from web service which is used for connecting to ...
5
votes
2answers
300 views

Are these good examples of functions that do one thing only or am I getting a little carried away?

I'm reading Robert C. Martin's "Clean Code" and for the past few days I've been fiddling with its function writing guidelines. At first I thought the idea of functions being two/three lines long to be ...
1
vote
0answers
57 views

Ascii Table in brainfuck

I made my first brainfuck program today, which prints the numbers 0-255 and the corresponding character. I was wondering if I could improve my program, as I'm repeating my self a lot (eg. 3 x copy ...
4
votes
2answers
186 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 ...
2
votes
1answer
117 views

Is there a safer/ more readable way of using this code?

Is there a safer/ more readable way of using this code? I gotta translate this code into a better , safer and more readable sample of code and get my onclick to work.(its currently called from another ...
3
votes
2answers
52 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; } ? ...