I am doing a java course through an online university.

I started the Tutor marked exercises today. A simple bit of java code. First they have you output a bunch of asterisks.
Then they have you output a different assortment of asterisks. To quote the directive

"Edit the program stars so that it prints five asterisks centered on the fourth line, three asterisks centered on the fifth line, and one asterisk cventered on the sixth line" Compile and run your program.

After giving the problem considerable thought, I started looking into importing some Java curses libraries, so that I could pull the number of columns from the active console display, divide the number in half, and either place the cursor in the right place or pad my strings with whitespace to achieve the same effect.

Which led me to the grim realization that I had just managed to turn a Java exercise of "Hello World" into bloatware.

So I did the right thing. I commented in that I was making assumptions about the number of columns, and then commented in a suggestion as to how to make the display always work using curses libraries.

But it still remains - I managed to bloat "Hello world"
ext_157608: (Default)

From: [identity profile] sfllaw.livejournal.com


Oh no. You just stumbled on the tip of the iceberg for terminal handling.

Why do you think ncurses and terminfo exist, hmm? And why O'Reilly published a hundred page book on them? Each?

From: [identity profile] chief1ic.livejournal.com


Lol, that reminds me of one of my favorite bits from Cryptonomicon:
-------------------------------------------------------------------
They gave him an intelligence test. The first question on the math part had to do with boats on a river: Port Smith is 100 miles upstream of Port Jones. The river flows at 5 miles per hour. The boat goes through water at 10 miles per hour. How long does it take to go from Port Smith to Port Jones? How long to come back?

Lawrence immediately saw that it was a trick question. You would have to be some kind of idiot to make the facile assumption that the current would add or subtract 5 miles per hour to or from the speed of the boat. Clearly, 5 miles per hour was nothing more than the average speed. The current would be faster in the middle of the river and slower at the banks. More complicated variations could be expected at bends in the river. Basically it was a question of hydrodynamics, which could be tackled using certain well-known systems of differential equations. Lawrence dove into the problem, rapidly (or so he thought) covering both sides of ten sheets of paper with calculations. Along the way, he realized that one of his assumptions, in combination with the simplified Navier-Stokes equations, had led him into an exploration of a particularly interesting family of partial differential equations. Before he knew it, he had proved a new theorem. If that didn't prove his intelligence, what would?

Then the time bell rang and the papers were collected. Lawrence managed to hang onto his scratch paper. He took it back to his dorm, typed it up, and mailed it to one of the more approachable math professors at Princeton, who promptly arranged for it to be published in a Parisian mathematics journal.

Lawrence received two free, freshly printed copies of the journal a few months later, in San Diego, California, during mail call on board a large ship called the U.S.S. Nevada. The ship had a band, and the Navy had given Lawrence the job of playing the glockenspiel in it, because their testing procedures had proven that he was not intelligent enough to do anything else.
.

Profile

luckytroll: Wearing my old fave hat (Default)
luckytroll

Most Popular Tags

Powered by Dreamwidth Studios

Style Credit

Expand Cut Tags

No cut tags