[Tutor] following on
alan.gauld at btinternet.com
Mon Feb 18 19:22:42 CET 2013
On 18/02/13 17:30, Matthew Ngaha wrote:
> i can attempt to use these libraries/frameworks/modules provided but
> how can i build or get better at creating/building my own tools?
Just build a lot of stuff. Its the only way.
> and i did that!" or hey i built my own engine, my own language!!
That doesn't happen all that often, usually people just extend
the existing language.
> etc... i become absolutely lost and thought i would like to do that!
What? Get absolutely lost?! :-)
> wondering if anyone could point me out to some good books or online
> tutorials that can teach me how to create my own modules, libraries
> that others could use.
In python this is almost trivial. Just create a Python script that has
functions or classes in it. That's it. Make it available for import by
putting it somewhere in your import path. job done.
There is a little bit more to creating a package rather than a module
but its easy once you've got the hang of making modules.
> This is what is called software engineering
No, its a part of software engineering. Software engineering is an
attempt to apply traditional engineering discipline to software
development in the hope that it will make the development process more
predictable, reliable and consistent. So far it's pretty much failed
because most "software engineers" don't really like doing hard math when
they could be writing code, and doing hard math before building anything
is pretty much what makes it engineering... (This is why some US states
refuse to acknowledge software engineering as 'real' engineering.)
But it also includes things like creating modular designs and performing
comprehensive tests and documenting the design in standard formats etc.
Those aspects have caught on in varying degrees.
> create custom instances and have these instances behave like normal
> python objects.
> I want my program to basically do EVETYTHING that
> python already does but in my own way. On the objects i'd like to
> perform stuff like __add__ or __cmp__ on them, but without actually
> using __add__ or __cmp__, get it?.
No, that's probably not good.
> I'll attempt my own built-ins also,
And that's almost certainly even worse.
> like summed() instead of sum()... is this a constructive exercise or a
> waste of time?
Its a waste of time given where you are on your learning journey. Maybe
some day you will have a valid need to create your own language but this
is almost certainly not it!
> understanding of how everything works.
Use it., Experiment with it. Break it.
Thats the best way. Read the source code its all available in
Python or C.
> like how can i make my own custom container and not have it
> subclass list(), and still act like a list()?
That's a more sensible option especially if you make it a type of
container that Python doesn't already have. Maybe a bag or a stack
or even a circular list. But there is no shame in inheriting from
list if that makes sense. That would be good software engineering -
don't reinvent the wheel!
> would i need to use stuff like __next__ and __iter__ or could
> i create my own that acts the same way
You need to implement all the special methods that give Python objects
their built-in behaviour. Or at least all the ones that matter, or make
sense, for your data type.
> ill drop the project if its a bad idea but if it isnt, its simply a
> work in progress(barely started).
I'd forget trying to rewrite Python in python. Even as a learning
project it has limited value and as a practical proposition no value at
all. Better to build something meaningful that pushes the envelope with
> so please point me out to some good books or online tutorials that can
> teach me how to create my own software that others could use. Also
> what is the correct term for this type of programming?
Just programming. Its what we should all be doing all the time!
> have any personal advice you could offer me, please do.. Thanks
When building reusable code start from the perspective of the user.
Write some tests that use the new creation even though it doesn't exist
yet. Make the code as easy to use as possible. Once you know how to use
it, start building the thing so that it can be used the way you want it
to work. The hard effort should be in building the reusable code not in
Author of the Learn to Program web site
More information about the Tutor