code-improvement

Alternative to Switch Case in Java

Is there any alternative way to implement Switch Case in java other than if else which is not looking good. A set of values will be there in combo, according to selection corresponding method has to be executed. ...

Simple, but can this be better?

This is just a simple check to see what letter grade to output. Is there any faster and more efficient way to achieve the objective? if ( $grade >= 90 ) { echo "A"; } elseif ( $grade >= 80 ) { echo "B"; } elseif ( $grade >= 70 ) { echo "C"; } else { echo "Failed." } ...

Which book should I pick to improve my program designs/design patterns?

I want to learn about design patterns and from what I've seen the most recommended ones are the Gang of Four's Design Patterns and Head First Design Patterns. There are also language specific books, but I never see them recommended. I suppose it ties you to whatever strengths/weaknesses are inherent to each language, so not a good idea t...

How to refresh screen so that closed forms actually disappear

I have multiple forms that popup during an intensive operation. For example, when a form popups asking user for something, and the user clicks OK, the form's graphics stay on the main screen, even though it is closed. How can I make it so that these graphics disappear completely? ...

improving regular expression to match all "http" only urls very neatly .

i have tried below given expressions. (http:\/\/.*?)['\"\< \>] (http:\/\/[-a-zA-Z0-9+&@#\/%?=~_|!:,.;\"]*[-a-zA-Z0-9+&@#\/%=~_|\"]) the first one is doing well but always gives the last extra character with the matched urls . Eg: http://domain.com/path.html" http://domain.com/path.html&lt; Notice " < I don't want them with ...

How can I improve this php code

Hi, I have a txt file that gets loaded and printed using a class. I'm relatively new to php, so I wonder if the class can be improved and some of the duplicated code (when printing the change-log) can be removed. Here is the class : class changesHandle { public function load($theFile, $beginPos, $doubleCheck) { // Open f...

How to start reading txt file from a specified line using PHP?

Hello, I have a txt file that has a change-log.I'm trying to display the new changes only for the current version. I wrote a function to read the file and check every line if it has the wanted words, if it finds those words it starts to get the content and push it to an array. I searched to see if there is an example but everyone was t...

Best Practices for Editing Hierarchical Data

I just finished making a change to an ASP.NET Ajax screen from a few years back. It was harder than expected to build and maintain. On this change, I estimated 12 hours and spent 4 days. Granted I also did extensive refactoring to simplify the code. This is actually some pretty fun code, but I wonder if there was a better route for the ...

How does a programmer employ deliberate practice?

How does a career developer sharpen and expand their skill set to reach the level of expert at their craft. A lot of scientific evidence points at the fact that experts become experts through many hours of deliberate practice. When we look at any kind of cognitively complex field — for example, playing chess, writing fiction...

A weighted version of random.choice

I needed to write a weighted version of random.choice (each element in the list has a different probability for being selected). This is what I came up with: def weightedChoice(choices): """Like random.choice, but each element can have a different chance of being selected. choices can be any iterable containing iterables w...

How can i improve this code in Java

private void somename(HttpServletRequest request, pageBean UTIL) throws Exception { checkEmpHxAction(request, UTIL); long empRecNum = UTIL.getNumValue("EMPLOYEE", "REC_NUM"); ListBean list = UTIL.getListBean(request, "EMPTRNHX", true); } My boss says that there is an improvement needed in the coding st...

Improving Swing layout

I have a following code : import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.Label; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax....