Kodi Arfer / Wisterwood

Attn Programmers: How do I get faster/better?

Topic List
#001 | ShadowSpy |
And when I say programmers, I probably just mean Kodi.

But honestly, I'm supposed to be a programmer but I feel like I'm just too slow at it. Any tips on improving?
---
"I always wanted to be somebody, but now I realize I should have been more specific."
#002 | Kodiologist |
"Slow" in a literal sense, you mean? What languages do you typically write in? How much freedom do you typically have as to your language and coding style (that is, are you writing for school or work or for yourself)?

---
"Ratio tile, the wish power are together with you."
#003 | ShadowSpy |
I'm mostly coding for work nowadays, and mostly doing Java. (There are times where I work with VBA as well. Eugh.)

I used to speed through school projects because they were small and designed to teach one concept at a time. But now that I'm working on larger projects, I spend more time learning APIs and researching functions than producing working code. On top of that, I get bored and lose focus when doing all that research because...well, it's boring.

So yes, slow in the literal sense...but I think it's more a problem of motivation, rather than a lack of skill. I feel like I'm approaching the situation from a wrong angle. How exactly do you approach your projects? I'm just wondering what I could be doing differently.
---
"I always wanted to be somebody, but now I realize I should have been more specific."
#004 | Kodiologist |
I think Java may be part of your problem. I don't speak it myself, but I know that it's a programming language designed to produce reliable code from large teams of mediocre programmers, rather than concise code from a few wizards; that it is extremely verbose and obstinately object-oriented by design; and that it has such a large library of toolboxes and libraries (with, as you've seen, have hyper-operational documentation) that programming in it has been described as "approach[ing] problem-solving like a plumber in a hardware store". It seems like the kind of language that, were I forced to produce programs in it, I'd end up writing programs in scripting languages to produce Java programs instead of writing in Java directly. So that's one idea! Write code generators or preprocessors in Python or the like, to factor out all the boilerplate code. Or write in Jython if you can get away with it.

From: ShadowSpy | Posted: 4/26/2012 8:30:12 PM | #003
How exactly do you approach your projects?

My strategy is generally to start on the hardest part first. You know how all but the easiest programs have some bits which are relatively mindless and others which are more difficult, for reasons intellectual (coming up with the right algorithm requires thought) or practical (there's a poorly documented feature you'll need to use, or you'll need to build an interface to two disparate systems). Begin by making that work. If the problem is both sufficiently difficult and sufficiently general, it can help to write a test suite before you start on the program proper. Once you have the hard stuff down, the rest is just cleanup and filling in the gaps, which is more gratifying than it sounds because it yields tangible results quickly once the hard stuff's done.

Any tips on improving?

Hmm. For me, one of the biggest differences between code I like and code I don't like is functional versus object-oriented or procedural style. That is, I prefer higher-order functions and deeply nested expressions over series of simple statements and loops:

Example 1:

bool $picked_blue = ($blue_on_right xor $picked_left);
(vs.)
bool $picked_big;
if ($blue_on_right)
{if ($picked_left)
{$picked_blue = 0;}
else
{$picked_blue = 1;}}
else
{if ($picked_left)
{$picked_blue = 1;}
else
{$picked_blue = 0;}}

Example 2:
sd = sqrt(
sum(map(lambda x: (x - mean(v))**2, v))
/ len(v) )
(vs.)
sd = 0
for x in v:
sd += (x - mean(v))**2
sd = sqrt(sd / len(v))

A functional style feels much more like saying what I mean, whereas a procedural style feels like stuttering. It's both easier for me to read and pleasanter for me to write.

Although this might sound obvious, don't neglect the opportunity to abstract away repetitive details into a function. It amazes me that people are comfortable doing fiddly SQL statement construction, binding, and execution in the middle of their application logic. I use the nifty Perl modules DBIx::Simple and SQL::Abstract and define functions liberally so I can say things like

my @u = $o->getrows('User', sn => $o->{sn});

instead of

my $sth = $o->{db}->prepare('select * from User where sn = ?', $o->{sn});
my $results = $sth->execute;
my @u = $results->hashes;

, although if I had to do it the latter way, I would, of course, instead write it as:

my @u = $o->{db}->prepare('select * from User where sn = ?', $o->{sn})->execute->hashes;

---
"Ratio tile, the wish power are together with you."
#005 | Kodiologist |
You might find this site helpful:

http://rosettacode.org/wiki/Rosetta_Code

---
"Ratio tile, the wish power are together with you."
#006 | ShadowSpy |
That summary of Java sounds about right. I'll give it a thumbs up, since it provides a reliable entry language for people interested in becoming programmers, but the phrase "obstinately object-oriented" is too true.

I've heard about Jython and considered learning it, but have just never gotten around to it. My Python skills are just a bit rusty, so maybe I should think up some Python projects and practicing with those.

As for the boilerplate code...yeah, Java has a lot of that. I would say that scripts for generating Java code have already been written though; Eclipse is a free IDE which takes away a lot of the tedium. Still, you make a good point that Java may not be the best language to use.

Kodiologist
Hmm. For me, one of the biggest differences between code I like and code I don't like is functional versus object-oriented or procedural style.


I agree. Looking at both your examples, it kind of hurts me to read the procedural style code, as compared to the functional. The thing about functional style is that it takes me longer to process the code if someone else wrote it...but once I've understood the code, it's no problem.

Kodiologist
You might find this site helpful:

http://rosettacode.org/wiki/Rosetta_Code


Looks cool.
---
"I always wanted to be somebody, but now I realize I should have been more specific."
#007 | Kodiologist |
One more thing: I assume you already know about Stack Overflow, but here's another site in the Stack Exchange family that you may find more directly useful:

http://codereview.stackexchange.com/

---
"Ratio tile, the wish power are together with you."
#008 | LinkPrime1 |
Might want to try this out.

http://www.youtube.com/watch?v=UUdV6lC7ZNI
---
Well, there is a new accent of n00b language. It's called: Vet LUEser goes Foreign!-MegaSpy22
Those must be the pants of the gods!-Digitalpython
#009 | ShadowSpy |
Ah, Stack Overflow is like a drink of fresh water after swimming through an ocean of useless question forums. <3

Code review sounds like a really good idea though.
---
"I always wanted to be somebody, but now I realize I should have been more specific."