From: Tad McClellan on
Justin C <justin.0912(a)purestblue.com> wrote:
> In article <slrnhhvmiu.69q.tadmc(a)tadbox.sbcglobal.net>, Tad McClellan wrote:

[ snip passing args instead of using globals ]

>> That is, it is fundamental Computer Science.
>
> Unfortunately that wasn't part of my education, all my programming was
> learnt post academia, under my own steam. If I'm lacking some of these
> fundamentals it's because the sources I leaned from didn't cover them
> adequately (or I haven't got there yet).


You might benefit from:

http://en.wikipedia.org/wiki/Global_variable
http://en.wikipedia.org/wiki/Action_at_distance_%28computer_science%29


> I did take 'computer studies' at school, I remember lots of punched
> cards,

[snip other nostalgia]

I was light on fundamentals too, as my undergrad was in Electrical Engineering
rather than Computer Science or Software Engineering.

After I switched from "hardware" to "software" work, I eventually
noticed that my projects would get to 80-90% complete, and then
stall in insurmountable cross-dependencies, or bad design decisions
made too long ago to undo.

I was fortunate enough to be able to go back to school and pick up
my missing fundamentals.

I'll share with you the most important thing I learned in slogging
through seven years (part time) of grad school:

Think before you code!

A quick google search leads me to recommend

http://www.codewalkers.com/c/a/Programming-Basics/Coding-Best-Practicesor-at-least-Better-Practices/

since they get to that right near the beginning.


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
From: Ben Morrow on

Quoth Justin C <justin.0911(a)purestblue.com>:
> On 2009-12-08, Ben Morrow <ben(a)morrow.me.uk> wrote:
> >
> > Quoth Justin C <justin.0911(a)purestblue.com>:
> >>
> >> I'm using Spreadsheet::WriteExcel, and (I think) I've created a
> >> reference to the worksheet. When I try to use this elsewhere I get:
> >> Can't call method ... on unblessed reference at ...
> >>
> >> This is the minumum I've been able to cut the code down to (sorry it's
> >> not shorter). The problem line is 26. As per the Spreadsheet::WriteExcel
> >> documentation I've created the object, and it's a reference to that
> >> object that I've passed from a subroutine to Main:: to pass on to other
> >> subroutines.
> >
> > An object is already a reference. You don't need to take another layer
> > of reference, just return the object.
>
> I think I'm getting the hang. I've been using references for ages,
> hashrefs, arrayrefs, but whenever I use objects I get a bit confused.
> It's coming together slowly now that I'd started working through the OO
> documentation.

Maybe you need to read perlboot. In simple terms, an object is just a
refrence with a bit of magic attached. Here is how you make an object:

my $obj = { a => 1 }; # an ordinary hashref
bless $obj, "My::Class"; # now it's an object

You can still deref this object with $obj->{a}, just like any other
hashref, but it's considered bad style to do so from outside the class
that defined it. (The author of the class is entitled to change the
internals in the next release, without warning you.)

However, you can also call a method on it, with $obj->method(...). This
is where 'My::Class' comes in: that is the package Perl will search
first for the method.

If you think of an object as much like an arrayref or a hashref you
won't go too far wrong.

Ben

From: Justin C on
On 2009-12-09, Tad McClellan <tadmc(a)seesig.invalid> wrote:
> Justin C <justin.0912(a)purestblue.com> wrote:
>> In article <slrnhhvmiu.69q.tadmc(a)tadbox.sbcglobal.net>, Tad McClellan wrote:
>
> [ snip passing args instead of using globals ]
>
>>> That is, it is fundamental Computer Science.
>>
>> Unfortunately that wasn't part of my education, all my programming was
>> learnt post academia, under my own steam. If I'm lacking some of these
>> fundamentals it's because the sources I leaned from didn't cover them
>> adequately (or I haven't got there yet).
>
>
> You might benefit from:
>
> http://en.wikipedia.org/wiki/Global_variable
> http://en.wikipedia.org/wiki/Action_at_distance_%28computer_science%29
>
>
>> I did take 'computer studies' at school, I remember lots of punched
>> cards,
>
> [snip other nostalgia]
>
> I was light on fundamentals too, as my undergrad was in Electrical Engineering
> rather than Computer Science or Software Engineering.
>
> After I switched from "hardware" to "software" work, I eventually
> noticed that my projects would get to 80-90% complete, and then
> stall in insurmountable cross-dependencies, or bad design decisions
> made too long ago to undo.
>
> I was fortunate enough to be able to go back to school and pick up
> my missing fundamentals.
>
> I'll share with you the most important thing I learned in slogging
> through seven years (part time) of grad school:
>
> Think before you code!
>
> A quick google search leads me to recommend
>
> http://www.codewalkers.com/c/a/Programming-Basics/Coding-Best-Practicesor-at-least-Better-Practices/
>
> since they get to that right near the beginning.

Thank you. I've forwarded this to self(a)home where I will have time to
study the information.

Justin.

--
Justin C, by the sea.
From: Justin C on
On 2009-12-09, Ben Morrow <ben(a)morrow.me.uk> wrote:
>
> Quoth Justin C <justin.0911(a)purestblue.com>:
>> On 2009-12-08, Ben Morrow <ben(a)morrow.me.uk> wrote:
>> >
>> > Quoth Justin C <justin.0911(a)purestblue.com>:
>> >>
>> >> I'm using Spreadsheet::WriteExcel, and (I think) I've created a
>> >> reference to the worksheet. When I try to use this elsewhere I get:
>> >> Can't call method ... on unblessed reference at ...
>> >>
>> >> This is the minumum I've been able to cut the code down to (sorry it's
>> >> not shorter). The problem line is 26. As per the Spreadsheet::WriteExcel
>> >> documentation I've created the object, and it's a reference to that
>> >> object that I've passed from a subroutine to Main:: to pass on to other
>> >> subroutines.
>> >
>> > An object is already a reference. You don't need to take another layer
>> > of reference, just return the object.
>>
>> I think I'm getting the hang. I've been using references for ages,
>> hashrefs, arrayrefs, but whenever I use objects I get a bit confused.
>> It's coming together slowly now that I'd started working through the OO
>> documentation.
>
> Maybe you need to read perlboot. In simple terms, an object is just a
> refrence with a bit of magic attached. Here is how you make an object:

I think, now that I'm looking more at OO that perlboot and perltoot (I'm
sure there's a third too) I'll find these two more accessible, and
therfore probably useful. Will add them to my reading list (again).


> my $obj = { a => 1 }; # an ordinary hashref
> bless $obj, "My::Class"; # now it's an object
>
> You can still deref this object with $obj->{a}, just like any other
> hashref, but it's considered bad style to do so from outside the class
> that defined it. (The author of the class is entitled to change the
> internals in the next release, without warning you.)
>
> However, you can also call a method on it, with $obj->method(...). This
> is where 'My::Class' comes in: that is the package Perl will search
> first for the method.

Yup, this is where you're losing me. I'll go to the documentation, I
fear it's going to take a little time reading, re-reading, and
re-re-reading to get some of this stuff. As I'm getting older I find
that practical (physicla) stuff goes in more easily, and abstract stuff
is getting harder to understand... that's no fun when the practical
stuff is no longer easy to do!

Justin.

--
Justin C, by the sea.
From: Sir Robert Burbridge on
On 12/10/2009 07:34 AM, Justin C wrote:
> On 2009-12-09, Ben Morrow<ben(a)morrow.me.uk> wrote:
>>
>> Quoth Justin C<justin.0911(a)purestblue.com>:
>>> On 2009-12-08, Ben Morrow<ben(a)morrow.me.uk> wrote:
>>>>
>>>> Quoth Justin C<justin.0911(a)purestblue.com>:
>>>>>
>>>>> I'm using Spreadsheet::WriteExcel, and (I think) I've created a
>>>>> reference to the worksheet. When I try to use this elsewhere I get:
>>>>> Can't call method ... on unblessed reference at ...
>>>>>
>>>>> This is the minumum I've been able to cut the code down to (sorry it's
>>>>> not shorter). The problem line is 26. As per the Spreadsheet::WriteExcel
>>>>> documentation I've created the object, and it's a reference to that
>>>>> object that I've passed from a subroutine to Main:: to pass on to other
>>>>> subroutines.
>>>>
>>>> An object is already a reference. You don't need to take another layer
>>>> of reference, just return the object.
>>>
>>> I think I'm getting the hang. I've been using references for ages,
>>> hashrefs, arrayrefs, but whenever I use objects I get a bit confused.
>>> It's coming together slowly now that I'd started working through the OO
>>> documentation.
>>
>> Maybe you need to read perlboot. In simple terms, an object is just a
>> refrence with a bit of magic attached. Here is how you make an object:
>
> I think, now that I'm looking more at OO that perlboot and perltoot (I'm
> sure there's a third too) I'll find these two more accessible, and
> therfore probably useful. Will add them to my reading list (again).
>
>
>> my $obj = { a => 1 }; # an ordinary hashref
>> bless $obj, "My::Class"; # now it's an object
>>
>> You can still deref this object with $obj->{a}, just like any other
>> hashref, but it's considered bad style to do so from outside the class
>> that defined it. (The author of the class is entitled to change the
>> internals in the next release, without warning you.)
>>
>> However, you can also call a method on it, with $obj->method(...). This
>> is where 'My::Class' comes in: that is the package Perl will search
>> first for the method.
>
> Yup, this is where you're losing me. I'll go to the documentation, I
> fear it's going to take a little time reading, re-reading, and
> re-re-reading to get some of this stuff. As I'm getting older I find
> that practical (physicla) stuff goes in more easily, and abstract stuff
> is getting harder to understand... that's no fun when the practical
> stuff is no longer easy to do!
>
> Justin.
>

A popular phrase floating around is that Perl's OO is "bolted on".
That's actually a good way of looking at it. A perl object is just a
hash (usually) on to which you bolt some subs.

That's really all =)

Like using a glue gun to attach a pinwheel to your cell phone ... now
you can do $phone->spin()

-Sir