tags: programming

Action executed in 0.000

Each Tag

programming

Common tags - number of posts

challenge (2), volunteer (1), PostgreSQL (1), database (1), handling (1), input operator (1), Towers of Hanoi (1), community (1), open (1), _answer (1), C++ (1), exceptions (1), TIGER (1), technology (1), map (1), beer (1), recursion (1), PostGIS (1), calculator (1), Java (1),

2 way join

challenge, programming

●●●●●○○○

Random Hacks of Kindness

rhok logo

To create a self-sustaining global community of innovators building practical open technology for a better world, and to ensure their work creates impact in society.

url: http://rhok.cc/

type: unknown, format: page

Challenge: Towers of Hanoi

Here's a new software challenge for us all. Take my project Towers of Hanoi and make it work. The goal is to write a recursive function to solve the game. Please print the towers after each iteration. The skeleton is already written. Just implement towers::execute().

A makefile is included. You may create new files, though i'm not sure that's necessary.

Please put your comments about the challenge under this "article" or email me directly.

Exceptions

What's wrong with this code? I'm not talking about the indenting style or casing.

If you haven't figured it out by now, it's the catch block. It does nothing. So called "software developer" may understand exceptions, but they don't understand the purpose of catching exceptions.

Let's assume your code or the code you call throws an exception. You have 3 options. (1) handle it, (2) don't handle it, (3) catch it and rethrow an exception.

(1) Let's say you're asking for a person's age. If the user enters "1O" (that's an oh not a zero), this should throw an exception when you convert it to a number. More importantly, the way you handle it is by reprompting, maybe 3 times.

(2) You can outright ignore it. In this case you must declare that you may throw it in the function signature. This is perfectly acceptable. In software, where input is not person-generated, for example reading a CSV file from a client, it's best to let that exception trickle right up through main and out to the developer. This is assuming you don't have to close files or database connections. At least this way YOU KNOW, there is a problem with the data. You can then edit the CSV and repair it. Or if the data is correct you can correct your code.

(3) There are cases, when you are implementing an interface or extending a class, that you can't change the function signature. Eg. public void HttpServlet.doGet( HttpServletRequest request, HttpServletResponse response ) throws IOException, ServletException. What happens if a NumberFormatException NFE occurs in this function? You must catch it. You should also throw a new ServletException( NFE ). This constructor specifies that NFE is the cause of our servlet exception.

The worst thing to do is, catch the exception and do nothing about it. This will hide errors in your data or your code.

Back to our age example... After 3 times, you've done all you can do to get the age. What should happen after the 4th time? You should catch the NumberFormatException, and throw a new Exception( "User is dumb.", NFE ). Let your callee handle it.

Programming

After a long day at work of arduous programming, i come home to do what? Yes more programming. But wait there's a difference. At home, i can sip my beer while waiting for code to compile.

At work today i was able to take the Tiger dataset and draw a map. Tiger comes with only line data, ie. only one dimensional. However for each chain of points there are attributes referring to adjacent polygons. Using tigerpoly.py in the GDAL project i was able to construct the 2 dimensional polygons.

All that data was inserted into a PostgreSQL database with PostGIS installed. PostGIS and GDAL needed a couple patches. Then i wrote a Java program to grab the data using JDBC and drew it using AWT. Sure Java2D is better, but i'm not sure i need it. After all i'm just drawing lines and polygons. Sheesh.

I'm guessing all map data comes from the same source. The Census Bureau. Therefore, even Google (eventually) gets their data from Tiger. How is it different? Well (1) the roads have width proportional to the number of lanes, (2) all the corners are rounded, and (3) their roads are labelled. Those are the major differences in appearance. As for differences in feel, don't get me started.

And on a side note, it's been so long that i almost forgot my password to my own website. Back to dinner (Otter Creek Alpine Ale).

infinite loop answer

After a little research i found this web page.

  • If std::cin is presented with input it cannot process, std::cin goes into a "fail" state
  • The input it cannot process is left on the input stream.

So "asdf" is not valid integer input. It is left on the input stream. Next time we read, same thing occurs.

What's the best resolution? After cin >> Command we can check the fail flag in cin with this if (!cin) { cin.clear(); cin.ignore( numeric_limits<streamsize>::max(), '\n' ); } then reprompt.

parent post: code snippet
notify me: yes

Stack, Expression Evaluation Challenge

Implement a stack. Use it to evaluate a simple mathematical expression. This expression will not have parentheses. It will use only plus, minus, multiply, and divide operators. The operands (input) will be integers, although output may be rational due to division. You may or may not use recursion. All code must be written by you.

Of course i'd like to see recursion. But if you think that's impossible then don't. When you see my example you will be proven wrong.

You swap out a stack for another data structure, but once again, don't wimp out.

Any code that is not used is seen wasteful and a bore to my eyes.

programmer

tags: programming
i might have to use you for your programming abilities. :oP
parent post: Website Split
notify me: yes