Octave Coding Style

18 views
Skip to first unread message

Dave Colwell

unread,
May 21, 2012, 2:20:23 PM5/21/12
to geekbo...@googlegroups.com
     I finished my second programming assignment for the ML class last night.  I'm starting to feel more comfortable with Octave and am wondering what "good" code looks like.  Mine so far is a bare-bones translation from Ng's math expressions into code.  I've been wondering if I should be using sub-functions to make my code more readable.  Also, I found myself manually running tests from the command line as I built up my code.  Seems like a good opportunity for some unit tests.  Are any of you doing more than "bare-bones" coding?  Maybe we could each print off our code to share at the coffee shop this Friday.

Dave

Grant Rettke

unread,
May 21, 2012, 2:51:22 PM5/21/12
to geekbo...@googlegroups.com
I'm curious to know what you come up with.

Sub-functions are great but they are not accessible by anything but
the defining function so they are not easily unit tested.

Defining every function in it's own file is of course the typical approach.

I like to use objects, they are easier to test, but I was told that
they are slower.

You can always use function handles to do something interesting.

I didn't dig very deep into this other than to reach the previous conclusion.
--
http://www.wisdomandwonder.com/
ACM, AMA, COG, IEEE

M. Krajnak

unread,
May 21, 2012, 11:57:33 PM5/21/12
to geekbo...@googlegroups.com
I don't think anything I've written so far was more then 4 lines, and about half were only one line, so I have not felt the need.

When I used to do a lot of matlab coding I'd break out sub functions first and promote them to full fledged functions If I had to share them.  Some unit testing, but it was pretty primitive.

Often I'd find myself writing a Java version of some prototype matlab code then write a unit test and generate the expected values using the matlab prototype.  Evil?  Probably...

Mike

On Mon, May 21, 2012 at 1:20 PM, Dave Colwell <dcol...@gmail.com> wrote:

Grant Rettke

unread,
May 22, 2012, 12:49:07 AM5/22/12
to geekbo...@googlegroups.com
I recently wrote a simulation in Java and called it from MATLAB to do
the plotting. It was very interactive and pleasant. Some might say it
was evil lol.

johnh

unread,
May 31, 2012, 9:04:21 AM5/31/12
to GeekBookClub
Quick note: I have added some helpful hints for programming exercise 4
to the course wiki (https://share.coursera.org/wiki/index.php/
ML:Programming_Exercise_4:Neural_Networks_Learning). Maybe they will
save you some time...

On May 21, 11:49 pm, Grant Rettke <gret...@acm.org> wrote:
> I recently wrote a simulation in Java and called it from MATLAB to do
> the plotting. It was very interactive and pleasant. Some might say it
> was evil lol.
>
>
>
>
>
>
>
>
>
> On Mon, May 21, 2012 at 10:57 PM, M. Krajnak <mdkraj...@gmail.com> wrote:
> > I don't think anything I've written so far was more then 4 lines, and about
> > half were only one line, so I have not felt the need.
>
> > When I used to do a lot of matlab coding I'd break out sub functions first
> > and promote them to full fledged functions If I had to share them.  Some
> > unit testing, but it was pretty primitive.
>
> > Often I'd find myself writing a Java version of some prototype matlab code
> > then write a unit test and generate the expected values using the matlab
> > prototype.  Evil?  Probably...
>
> > Mike
>
> > On Mon, May 21, 2012 at 1:20 PM, Dave Colwell <dcolw...@gmail.com> wrote:
>
> >>      I finished my second programming assignment for the ML class last
> >> night.  I'm starting to feel more comfortable with Octave and am wondering
> >> what "good" code looks like.  Mine so far is a bare-bones translation from
> >> Ng's math expressions into code.  I've been wondering if I should be using
> >> sub-functions to make my code more readable.  Also, I found myself manually
> >> running tests from the command line as I built up my code.  Seems like a
> >> good opportunity for some unit tests.  Are any of you doing more than
> >> "bare-bones" coding?  Maybe we could each print off our code to share at the
> >> coffee shop this Friday.
>
> >> Dave
>
> --http://www.wisdomandwonder.com/
> ACM, AMA, COG, IEEE
Reply all
Reply to author
Forward
0 new messages