Is this you? As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.
Claim your profile
Articles by Ethan Bierlein
Floating point equality in Java - follow-up
This is a follow up post for this question. There aren't a lot of changes. The changes (all of them major) are: Basically, I fix my code when someone manages to break it. Tom Leek opened my eyes. Spotted's answer was nice too, but it's too bad that it must be done in a slightly different way to ensure compilation. It was a nice feeling when I saw my code pass in the cases mentioned by Tom Leek. Now, for the cases mentioned by Tom Leek: The above code runs without resulting in any assertion errors.
Stack Implementation in C++
You shouldn't be using , as you did in various places, like here: is deprecated, and you should be using , like this: If this is legacy code, and you need to support users running old compilers that date to before C++09, you should keep using . Rather than using , you should just prefix this onto the end of any statements: You should be doing this unless you're very sure that you want to flush the output buffer each time you run .
E-mail testing code
Switching between GUI input and console output You take your input via a JOptionPane, but the output of your validation is displayed via System.out. It will be much better UX-wise to show the result as another dialog box too. Braces Please use braces, it's not that hard. One extra line here or there and your conditions/loops will look even messier to clean up. Boolean assignment and evaluation if(dot1==0) dot=false; else dot=true; This can be rewritten as dot = dot1 != 0.
Code Review Stack Exchange
Your mathematical criterion for equality has some issues. One important point to consider is that your "equality" is not transitive. In your code, you use a threshold of \$\epsilon\$ (\$\epsilon = 5\times10^{-16}\$ in your code, when the values have type ); you declare \$x\$ and \$y\$ to be equal to each other if \$|x-y|\leq \epsilon\$. Now suppose that you have three values \$a\$, \$b\$ and \$c\$ such that \$b = a + 0.9\epsilon\$ and \$c = a - 0.9\epsilon\$.
C++ Stack using template
Rather than relying on , you should use an include guard in your file instead, like this: While is supported across many compilers, there's always the chance that there is one that doesn't support it because it still isn't standard.
Getting a scrabble score from a word
@Ethan's review already mentioned the basic improvements, but I think that there are other things you could improve and experiment with. At the end of this review I've put together a working example of the refactored code, so you can refer to it for all the things I'm mentioning. When your program consists of a single source file, you might as well avoid declaring function prototypes and put the other functions above .
Full C++ Snake game
Rather than using and creating a bunch of macros like this: You should use instead, like this: I'd also define your structure as a class, instead, like this: But that's not all we can do, we can also remove the empty constructor, as it doesn't make much sense to have it. Our class then becomes this: But that's still not all. There's a better way of initializing and in the constructor as well.
How does getpid work?
The kernel does job scheduling and provides system calls. When a process is running, the kernel schedules its runtime - especially it assigns a PID to it - such information is stored inside the kernel address space, in data structures (e.g. inside a task struct). Thus, when a process calls the system call, the kernel just has to look in the task structure of the calling (i.e. currently running) process.
Code Review Stack Exchange
This is an implementation of the Nothing programming language. The language spec is as follows: In the current software industry focus lays on solving complex problems by using complicated algorithms. The language "Nothing" was created to shift this focus from complex problems towards the expectations of the programmer and the user. This way even the most complicated programming challenges swiftly disappear as if they never have existed before.
Simple RPG skeleton - Part 1
This does not make it more random and can affect the quality of numbers you get. Random engines have some state. Generally you only want one engine, though you can have more, but you don't want it to be recreated everytime the function is called. This answer does a good job of explaining it: "... Think of a random number generator where the seed must be maintained on a per-thread basis. Using a thread-local seed means that each thread gets its own random number sequence, independent of other threads.
SPOJ solution of GRAVITY
I cannot review the content of your code because it is very, very unreadable, but I just wanted to point a few things out. According to the signature, is supposed to return an . However, run of the return cases is , which is merely a constant assigned to ; that's not necessarily an . Therefore, when creating the constant , you should use and a type. This will ensure that is actually and . You variable names are very poor.
Find the perfect numbers within the range of 1 and a chosen number
MS specific don't need it here Never do this. I know every book you read does this. This is because they are paying for the ink. Its actually very bad style and will cause a huge amount of problems for any program longer than ten lines or for code that lives longer than a year. So it is bad habit you should get out of the habit of doing. The reason they picked rather than so it is easy to type and use as a prefix. Its not that much harder to type than the normal object or type.
How can I remove a forkbomb from the Startup folder?
Try booting your laptop in Safe Mode by pressing F8 during the bootup sequence, from there, just locate the file in your Startup folder and delete it. If you're worried about accidentally opening it, or something similar, you can boot up in Safe Mode with Command Prompt (Provided you can use Command Prompt), and delete it that way, instead.
How to remove a forkbomb from the Startup folder?
Try booting your laptop in Safe Mode by pressing F8 during the bootup sequence, from there, just locate the file in your Startup folder and delete it. If you're worried about accidentally opening it, or something similar, you can boot up in Safe Mode with Command Prompt (Provided you can use Command Prompt), and delete it that way, instead.
Generating a password to save to a .txt file
Regarding the code (not making it stronger!): You can get random letters let1, let2, etc... much easier, simply: let1, let2, let3, let4, let5, let6, let7, let8 = random.sample(string.letters, 8) See more about random.sample here.
Console window to debug Windows Applications
Since I was having some difficulties to debug the next step for Scrolly - A (very) simple infinite mouse "scroll", I've decided to make a console-like class that allows to add messages to it. This allows you to show some messages. It also allows to pass any object you want, but it will be converted to string. You can add information, error and warning messages as well, which will have a matching color for each. It is quite a long wall of code, I know.
Performing and timing loops
In the case of both if your loops, you could easily make them loops instead, which tends to be the best practice. Should be rewritten as: This allows you to recycle the variable later, and also prevents from accidentally forgetting to reset back to between loops. Generally, the variable stands for , and is typically reserved exclusively for loops. This has no real performance impact, but it has a severe readability and maintainability impact.
Guess a random number between 1 and 100
Right now, as it stands, you're just converting any user input to a integer, using the function. What do you suppose happens if the user enters something like ? What you need to do is set up a - block, like this: To set up something like this in your code, you'd change your code to something like this: Rather than printing a message saying that if the user got below a certain amount of tries, they win, you can implement it into the code.
Text based fight game
You are repeating yourself in a lot of places in your code. In fact, I'd say most all of your code is just a giant repeat. You have 4 functions in your code. These functions are almost exactly identical, except for a few tiny points. Each function is doing the same thing: getting two random numbers, logging them out with a message, and then running some conditionals on these numbers to determine what other message should be sent. Therefore, why don't you stick these all into one function?
Solution to the 0-1 knapsack
Your code is very hard to follow. Your variable names tell very little about what they are supposed to be, and there are mysterious things, like why is a 2-tuple, when only the second value in it is used. The very long lines make it hard to follow as well. It is also not obvious to figure out which of the values in every item is the weight and which the value.
Locating a PID based on an IP address and port
First off, a couple of quick tips: No need to work with yourself. For example you can simply remove these lines: The way you specified the ip-port arguments with , will take care of validating the number of command line arguments. You can omit . But in that case, the value of will not be a list, but a simple string. You can also omit the , as that's the default. Your usage would become simpler: It's awkward that use , the splitting at multiple places is just noise.
Finding the kth to last element of a singly linked list
Before I say anything, let's reformat your code, for everyone's sake, because as you posted it, it just doesn't work, because indentation is crucial in Python. Please be more careful next time. This is not what the posted code does. The function searches for an element with the specified value, and prints that element and the rest of the elements until the end of the linked list that are bigger than the the specified value, or else it prints the text "Not exist".
How can I destroy a block from afar?
I've been playing on the PPCG Minecraft server for a little while, and I've managed to build a fairly decent tower, but someone has decided to do this, right next to the top: While I could build out and get it, I don't have a silk touch pickaxe, which means I'd have to make more glass, and I'd lose some resources due to the height as well. Is there any way that I can destroy this block from afar? Do note, I don't have command privileges.
How can I model a star?
I'm trying to model a star in Unity, and it, sort of works, but it's not ideal. Currently, I'm using a large sphere with a self-illuminating material containing a star texture applied to it's surface, and a spotlight to create the effect of starlight, like this: While it works, it doesn't look the greatest. I'm looking for an effect more along the lines of how Kerbal Space Program models a star: How can I achieve this effect?
Electrical Engineering Stack Exchange
It's important to understand there's a difference between a half-adder and a full-adder. A half-adder is the simplest. It has 2 inputs and 2 outputs. It's basically a XOR. The primary output is only 1 if one of both inputs is 1, but not if both are 1. That's . The second output is only 1 if both inputs are 1. That's . That's nice, but only if you're adding two bits. If you need more bits, you'll have to combine some adders together. Here's where full-adders come into play.
Very simple inventory system
To learn F#, I've implemented this very simple inventory system. While I'm proud that that it's my first program, and that it works, there are still a few areas that I'd like tips on, namely these: I don't like how I'm using a loop in to find the length of . Is this the correct usage of F#'s type/class system? Should this be made in a more "functional" way? Am I using getters/setters correctly? Do I need to declare the variables in my s, or is this automatically done?
Random number guessing
For a beginner I would consider this code to be pretty good. The code structure is clean, and has nothing "superfluous" - all the code is necessary, and the use of standard library functions to do the work is great. The only real criticism I have is in the variable names. , , and are crummy names. With a simple variable rename, your code is significantly better: Hmm, that makes a few things more obvious....
Calculating Parking Fees
You're inconsistent with how you place your curly braces, . The general style for Java is to place opening curly braces, , on the same line, like this: This goes for loops, classes, statements, etc. Even though for one-liner statements, curly braces aren't necessary, I'd still recommend using them. This means that a statement like this: Would become this: Not using curly braces can lead to some not so great mistakes happening. A famous example of this is the Apple SSL bug.
Popular questions by view count
You use good local variables, and you are consistent with your naming. The typical naming for T-SQL is using , however there are no standards and or work just as good, as long as you are consistent (which you are). You validate your values, although I am not quite sure why you chose 500 and 3 as arbitrary minimums (might be worth documenting). As written, your query returns this: Which is all well and good, except, it doesn't give much information.
Python script to create Android/iOS strings from a .csv
My script takes a CVS file of strings and then creates an XML file for Android and a .strings file to be used for iOS. It separates each locale meaning that a file will be created for each language. This has come in handy so far, making localising mobile apps easier. However, I am always seeking feedback so let me know what you think.
Percentage of questions that are unanswered and answered
Your comments are mostly clutter, and I mean that because your naming is good enough to where the comments are mostly irrelevant. Also, if you do need to make multi-line comment, you can use the same syntax in SQL as in pretty much everything else.
Creating Original Database Algorithm--Login System
In your function , you should close the file at the end of the file because this frees up any system resources that were being devoted to working with that file. For some reason, at the end of that function, you commented out the line You should un-comment this. In python, it is good practice to open a file using the keyword. Using , you can easily access the file object and the file is automatically closed at the end of the statement.
Simple game of Hangman
This looks like the kind of code that would be in a function to print out multiple strings in array. However, since you only have one message that is in an array, this seems kind of overkill, especially since there are only three lines. It would be a lot easier just to print out the message as it is: Instead of trying to get your own list of words, I recommend trying one of these three options: There are probably tons of API's on the internet that will serve as a dictionary for your program.
Web crawler that filters out non diseases
Here are some suggestions: More comments and docstrings would be nice, so the reader/reviewer can see what you intend the code to do (why was the code written this way?). It makes it easier to follow, because your intention is clear, and also then I can spot bugs where the implementation doesn't match the indentation.
Simple game of Hangman in Python 3.4
This looks like the kind of code that would be in a function to print out multiple strings in array. However, since you only have one message that is in an array, this seems kind of overkill, especially since there are only three lines. It would be a lot easier just to print out the message as it is: Instead of trying to get your own list of words, I recommend trying one of these three options: There are probably tons of API's on the internet that will serve as a dictionary for your program.
Removing duplicates from an unsorted Array
It's recommended to use an enhanced for-each loop instead of a counting loop when possible: And you can get rid of , as already contains that same information: I noticed later that your original code does an unnecessary comparison for the first element or : it would be enough to iterate from the 2nd element.
Most Common Letter in string
First off, after doing a little reading, the style for ruby seems say that you should indent your code by two spaces, not four, like Python. Secondly the line can be shortened to this: . Rather than using a loop, and a variable, , as an iterator variable as shown in the below code: You could use a loop instead. By using a loop, you don't need to declare an iterator variable, , and it looks cleaner as well. Finally, you could use some better names for your variables.
Calculator in C#
I'll blame the extra-weird broken indentation on copy/paste difficulties, and ignore that. There are as many ways to write a calculator as there are programmers willing to write one. So I'm not going to suggest other ways, instead I'm going to hint at how you could improve the flexibility of what you've got. The first concern you have, is getting user input. Your code works when the sky is blue and the user isn't being too clever. What happens if you play the QA engineer here?
50 State Info Program
In , the variable is unused. The method iterates over all entries in , even after it found a match. It could return immediately, and without using the local variable: The other inefficiency is that looking up a state by iterating over a list is an \$O(N)\$ operation, and you can do much better by building a , turning it into an \$O(1)\$ operation, which is especially important if you intend to do this repeatedly. Exiting in the middle of the program with is not pretty.
Another JavaScript Stack Exchange chat bot
I've been inspired by @SirPython's SirAlfred JavaScript chat bot, so I went and made my own. This one is slightly different though, in the fact that it can accept input in a more lenient way. For example, here's a "conversation" with the bot: Essentially, instead of directly checking the contents of the string, it removes all non-alphanumeric characters, excluding spaces, and then splits on a space.
50 states info program
In , the variable is unused. The method iterates over all entries in , even after it found a match. It could return immediately, and without using the local variable: The other inefficiency is that looking up a state by iterating over a list: for example to find "Wyoming", the program has to step through all previous elements. If you use a instead of an array, then lookups can be instantaneous or close to that. Exiting in the middle of the program with is not pretty.
Election vote-counting, result-posting chatbot
To address your first concern, the way you're doing colors is fine... If you're not running Windows. If you try to use raw ANSI codes like this on windows, you're going to run into some issues. Personally, I'd recommend using the Colorama. It's pretty easy to use.
Very Ugly Tkinter Calculator
def enter(): global x if x == 'add': answer = Entry(main) answer.grid(row = 0, column = 3, columnspan = 30) answer.insert(0, "%f"%(string[0] + string[1])) #Label(main, text = "%f"%(string[0] + string[1])).grid(row = 0, column = 3) #tkMessageBox.showinfo( "The Answer Is:", "%d"%(string[0] + string[1])) elif x == 'sub': # Label(main, text = "The answer is: %d"%(string[0] - string[1])).pack() # tkMessageBox.showinfo( "The Answer Is:", "%d"%(string[0] - string[1])) # Label(main, text =...
The chatbot for The Community Post Pimping Board
I recently wrote a chat bot for a chat room here at Code Review. The chatroom is meant to be a place where people can come and pimp a post. That chat bot is meant to handle a list of subscribed people and a list of pimped IDs. Note: This bot is still a work in progress. This is the first working version of the bot. There are 3 commands in the chat room: When a post is pimped, a notification is sent out to everyone on the subscribed list. Then, the link to the post is printed out.
Imposing a sort order on a query
Despite Dijkstra's famous essay, does have its uses. However, in C#, it is very unlikely that you would encounter a situation where is truly the best option. C# explicitly provides a set of specialized keywords like and that are meant to be limited s designed for use in those specific cases that call for , and only them. Since these are much more limited than , they do not harm readability because they are much more predictable. With a , who knows where the is.
Readability and Goto
I've always been told "never use goto, there's always a better way" and for the longest time I just accepted it. Lately though, I've been running into such scenarios in which I have to repeat this bit of code every time I return early. I personally hate repeating myself, even the littlest bit of code. So I ask, Is this use of goto really that bad?
Very simple Python preprocesser that allows "until" and "unless" statements
I've implemented the beginnings of a Python preprocesser I plan to implement sometime in the future, and the below code is my simple prototype. At the moment, it only converts and statements. For reference, here's an example of a code file using and , before it's preprocessed.
Enumeration of random trees
I'm interested in recursive generation of trees in Python. For my eventual application, it's important that the trees be represented as a list of nodes (rather than say a dictionary, or an edge list, or some other format). Also, in my eventual application, each node of the tree will have between 0 and hundreds of children. In this skeleton code, the number of children for each node is generated randomly.
Object-oriented JavaScript and Google Maps objects memory management
Fist of all check this article about memory management, it will help to find leaks if any. Look closer at this part There is a limitation when it comes to cycles. In the following example two objects are created and reference one another – thus creating a cycle. They will not get out of the function scope after the function call, so they are effectively useless and could be free'd.
Populating a bag of Scrabble tiles
I'm sorry, I just love to make things flexible so much that I have to take it one step further... I will use a mix between @EthanBierlein's version and your original, and improve on that, making the following changes: There is really no reason in my opinion to separate the configuration of how many tiles of a certain letter there should be, and how many points that tile should be worth.
Show More
loading
Actions
Is this you?
As a journalist, you can create a free Muck Rack account to customize your profile, list your contact preferences, and upload a portfolio of your best work.Get in touch with Ethan
Contact Ethan, search articles and posts on X, monitor coverage, and track replies from one place.
Learn more about Muck Rack