poke
  • Member for 10 years, 11 months
  • Last seen more than a month ago
Simplifying conditional statements for transaction code
Accepted answer
11 votes

You could do it like this: public void func() { if (string.IsNullOrEmpty(customerpay) || string.IsNullOrEmpty(warrantypay) || string.IsNullOrEmpty(maintanceplan)) return; if (...

View answer
Sorting a list of first names from a text file
10 votes

Use File.ReadLines to read from your file. This makes everything a lot simpler and avoids having to work with stream readers and buffers. You will just get back every line, so you don’t have too much ...

View answer
Hangman game code refactoring
7 votes

Some comments: Make sure you have a consistent indentation style. It makes it difficult to follow the code flow, if there are multiple lines with different indentation. You should separate the view ...

View answer
Project Euler #3 - how inefficient is my code?
5 votes

You can save quite a bit time on your prime generation. What you should keep in mind is that a prime is a number which is no multiple of a prime itself; all other numbers are. So in your isPrime ...

View answer
Printing numbers in lexicographic order
Accepted answer
4 votes

Okay, let me point out some stylistic things first: Doing traceback.print_exc() in an except block feels somewhat odd. Either you hide the stack trace by printing your own error message—which is ...

View answer
How to find the unique values from the JSON file?
4 votes

So… I have spent a bit time on this and generated myself a random JSON file matching your format. Mine is 167 MB in size, so not too far off from yours. First of all, ijson’s performance is terrible. ...

View answer
Image-processing filters using decorator pattern in Python 3
3 votes

First of all, since Python is dynamically typed, there is not really a need for interfaces. That’s why there is no such language concept. So your IImage type does not really serve any need. Similarly,...

View answer
Hangman in Python
3 votes

Some ideas: You might want to make sure that the guess is actually a single letter. lettersGuessed should be a set, so membership tests (guess in lettersGuessed) is a constant time operation. ...

View answer
Get count of positive numbers and sum of negative numbers
2 votes

To avoid iterating the input list two times, you should just use a normal for loop and two counters: def manipulate_data(data): positive_count = 0 negative_sum = 0 for n in data: ...

View answer
Alternate checked between buttons
2 votes

Simply collect all the buttons in a list, and then you can use a single event handler for all the check buttons: private List<ToolStripButton> buttons = new List() { toolStripButton1, ...

View answer
Generating a table of differences between two dictionaries
2 votes

You should separate the logic from your representation and first collect those differences in a separate list. Also, what are the types of your dictionaries? All those ToString()s make it really noisy ...

View answer
Function for shuffling cards
Accepted answer
2 votes

First of all, you are not supposed to modify the list in-place. Instead, return a shuffled copy of the original list. This is also checked by this doc test: >>> cards[:12] # Should not be ...

View answer
Number letter counts
Accepted answer
2 votes

Here are a few things: container.__len__() – You should never call magic methods directly. Just use len(container). As you don’t know to what amount you need to increment (i.e. your COUNTTO), it ...

View answer
Dynamic wrappper used to unit test ASP.NET Core MVC Controllers that return anonymous objects
1 votes

This is a really interesting solution. However, I don’t really see how this is ultimately useful. If I wanted to unit test an anonymous type, instead of testing if all properties exist on it all the ...

View answer