473,769 Members | 5,471 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to actually write a program?

Hello there,
I have been on and off learning to code (with python being the second
language I have worked on after a bit of BASIC). What I really want to know
is, if you are going to actually write a program or a project of some sort,
how do you actually start.

Picture this, you know what you want the program to do (its features), you
have a possably rough idea of how the program will work. You have opened an
empty text file and saved it as 'mykewlprogram. py' and now your sitting in
front of an empty text file... Now then.... where do I start.

Any ideas about this problem :-)

Ta
Nick
Jul 18 '05
33 3490
"Nick Evans" <ni**@huff.org. uk> writes:
Hello there,
I have been on and off learning to code (with python being the second
language I have worked on after a bit of BASIC). What I really want to know
is, if you are going to actually write a program or a project of some sort,
how do you actually start.

Picture this, you know what you want the program to do (its features), you
have a possably rough idea of how the program will work. You have opened an
empty text file and saved it as 'mykewlprogram. py' and now your sitting in
front of an empty text file... Now then.... where do I start.

Any ideas about this problem :-)

Ta
Nick


1. This problem comes up even for experienced programmers. You may have
done project planning, data models, UML diagrams, GUI story boards,
test suites, etc. Yet one day you need to mentally shift gears and
actually write code. A more experienced programmer will have done
some prototyping while working out the requirements and specs, but
even then it is a difficult mental transition.

2. For a total novice, get one of the tutorial books (e.g., "Learning
Python" or "The Quick Python Book") and follow through a few of the
examples. Don't do all the examples. All you need from this phase is
confidence that you can write working code, and general awareness of
the existence of language features. ("Yep, I know Python has
exceptions. Don't know how they work exactly, but I know they are
there.") You can learn the details when you need them.

Traditionally this exercise is done as a "hello, world" program, with
gradually increasing complexity as you tack on more and more language
features. It can be the most frustrating program to write in any
language. The problems are mostly "stupid mistakes" -- that is a
normal part of learning new languages. [It is also a normal part of
advanced programming, which is why test suites and peer reviews are so
powerful.]

3. Once you can do "hello, world" stuff, then tackle your project.
Assume your first effort will be a bad design, so plan to
"write one to throw away".

Even if the app eventually is a GUI app, start with a batch processing
approach. Do this by doing a reader/writer process around the data
model. The "model" (from model-view-controller) is a class with a few
attributes. The controller is a class that has a sequence of those
class objects, a method to read an input file to load that sequence,
and a method to write the sequence back out.

In fancier settings, there might be persistence via a database or
pickle, or the input and output may be XML or csv. But for starters,
just use a line-per-record file with ":" field separators.

4. Once the "model-controller" is working, it is time to set up a
proper project. One approach is my mkpythonproj at:
http://www.seanet.com/~hgg9140/comp/index.html

However you do it, you need a project with documentation, testsuites,
and a setup.py for sdist tarballs. Put it under config control (e.g.,
cvs or svn). You may want to factor out the "model" and "controller "
to separate modules. You are also ready to read good code examples,
so scan "Python Cookbook" and other resources.

Once the project is established, you can begin adding more complexity
to the "model". More classes, more attributes, more interlationship s,
edit routines, etc. Maybe add more import/export mechanisms (pickle,
csv, XML, etc.).

5. If there is to be a gui ("view"), storyboard (sketch on paper) a
few of the dialogs you will need to drive the "controller " methods.
Assume 1 dialog per model class, plus a tree or list widget
representing the controller's sequence or dictionary of data.

You must decide which toolkit to use. Tkinter, wxPython, PyQt,
PyGTK are the main contenders. Now, set aside all the work you've
done so far and concentrate on learning the GUI toolkit. Get a main
window working, with menus, file open/close, exit. The file
open/close of course call the file reader/writer you already have
working.

Next build a dialog to edit one of the classes, using the same edit
routines you have already developed. Hook the dialog to the "edit"
submenu.

Tag the release in your config control system, and make a tarball
(version 0.1).

6. By now you have a much better grasp of the project, the language
and the available libraries. It is time to rethink the project.

Print out the code ("enscript --line-numbers --landscape" is a good
choice). Read it.

Do this mental exercise: You have an opportunity to work on a
wonderful new project, if only you can train a replacement for
maintaining the current project. If you fail to train the
replacement, of if they leave in disgust, you are doomed to maintain
your own code forever. What can be done to make the handoff painless?
Refactor? More systematic approach to method naming? Better
"developer' s guide" documentation? Move hard-coded values to tables,
config files, dictionary lookups?

I find that on some projects, I can fix the code in situ. Most times,
I just make a whole new project and start fresh. Either way, the
target is code clean enough to be a pleasure to read and maintain.


--
ha************@ boeing.com
6-6M21 BCA CompArch Design Engineering
Phone: (425) 342-0007
Jul 18 '05 #31
>>>>> "Peter" == Peter Hansen <pe***@engcorp. com> writes:

Peter> Ahhh!!! Run away some more! UML and XP are nearly
Peter> anti-thetical. Don't even consider going there. (Well,
Peter> consider it, but please don't waste any money buying a UML
Peter> book as you do. Find a few web sites, then ... run away!
Peter> It's cheaper that way.)

There should really be a pythonic alternative to UML. I'm talking
about a textual format that can be rendered to pretty graphical
diagrams for PHBs/project managers to drool at. Text format would be
easy to edit with just an editor, it would be version-controllable,
scriptable, blah blah. I bet a lot of anti-UML attitude can be
attributed to the clumsy, non-programmery process that manipulating
UML images graphically involves.

I'd like to "draw" sequence diagrams like:

object user, slot,sensor, beeper

user - slot insertCoin(0.20 )
slot - sensor report(1,0.20)
sensor - beeper trigger()
user - slot insertCoin(0.20 )
...

etc.

Then I could easily insert new stuff retroactively by just editing the
file, without having to load the thing into some horrible bloated
expensive peace of (krhm) software that breaks the image into
irrepairable mess by just having the user click on the wrong widget.
--
Ville Vainio http://tinyurl.com/2prnb
Jul 18 '05 #32
Ville Vainio wrote:

There should really be a pythonic alternative to UML.

<snip>
Hello,

I've not commented about my original UML post because I didn't
want to start a row about UML. However I do like your idea of a simpler
cleaner UML to allow to go back and forth without needing a full blown
UML case tool. The thing I really like about this is that you could
write this and easily convert it into your source code (if round-trip
engineering yanks your chain) or to XMI so it can be exported/imported
from/to other systems. I'm gonna have a go at writing one of my designs
(sequence is easy - class would be more difficult) down in a pure way to
see if I can get it to be readable, clean and obvious.

On the XP side, sorry but I do think that the two really do go hand
in hand - every XP programmer will have an overall idea of how the
system works (on paper or in head), if it is a team of programmers then
you will have a design written down somewhere (or how do you all work
together). In addition, every UML 'round-trip' enthusiast will have
some tests in their code - it may not be as rigorous as XP but they will
have tests.

To my mind the best solution is to have both systems - trying to
understand a large 'enterprise' class system without UML can be a real
pig. If I have the class diagram(s) with supporting sequence diagrams
then I can easily work out how it all fits together. If I have the
tests written for me then I can run the tests for each module of the
system and investigate the behavior under the various conditions as laid
out in the requirements specification.

One other thing about XP, tests are also excellent for the
maintainability of code, running the tests on all code in your source
repository (at midnight, when else!!) and reporting back the errors
really allows you to keep a hold on your body of source code.

Anyway my new laptop with an English (read British, the pound -
currency - sign is proudly sitting above the 3 where it should be!)
keyboard has just turned up so I'm gonna have a play!!

Cheers,

Neil

--

Neil Benn
Senior Automation Engineer
Cenix BioScience
BioInnovations Zentrum
Tatzberg 47
D-01307
Dresden
Germany

Tel : +49 (0)351 4173 154
e-mail : be**@cenix-bioscience.com
Cenix Website : http://www.cenix-bioscience.com

Jul 18 '05 #33
On Wed, 08 Sep 2004 10:22:06 +0200, Neil Benn <be**@cenix-bioscience.com> wrote:
Ville Vainio wrote:
There should really be a pythonic alternative to UML.


For some reason I could not find the original post, but I'll second
that. UML is good, but for some reasons I couldn't find good tools to
support productive Python programming using UML. It's actually a big
quest -- the entire toolset ranges from solid (and standard) DB
support to two-way UML engineering tools -- but the main problem for
me is the lack of a common idiom to express some of the business
abstractions in Python. Each and every package assumes a different way
to write or structure the code. This is of no help.

--
Carlos Ribeiro
Consultoria em Projetos
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: ca********@gmai l.com
mail: ca********@yaho o.com
Jul 18 '05 #34

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
5767
by: dataguy | last post by:
I can't find it anywhere in the manual, but I have a developer that wants to know if we can code a trigger to capture the data that has changed in a table only if certain columns have changed. It looks like I can do it with the when clause and check the old vs new, but that would get very ugly with a large table. Has anyone done something like this?
2
3070
by: Jeevan | last post by:
Hi, I have an array of data (which I am getting from a socket connection). I am working on a program which acts on this data but the program is written to work on data from a file (not from an array). I cannot change anything in the program but can add some features by which I can convert this array of data into a file. The easiest thing would be to write the data into a file (in hard disk) and use it. But I will be working on thousands...
18
3711
by: jacob navia | last post by:
In C, we have read-only memory (const), read/write memory (normal data), and write only memory. Let's look at the third one in more detail. Write only memory is a piece of RAM that can only be written to, since its contents are undefined. The program is allocating a new piece of data, and the previous contents aren't relevant. This memory
15
1403
by: John Salerno | last post by:
Ok, I've been reading an intro book to C# and I'm learning a lot of the basics. I can follow along with all the sample code and understand exactly what it's doing, but I know there's no way I'd be able to write the code myself. Also, it seems like every time I come here, or read info online, there is so much complicated stuff that I haven't even seen yet. Basically what I'm wanting to know is, how long do you expect it to take a...
13
2067
by: Jacek Dziedzic | last post by:
Hi! <OT, background> I am in a situation where I use two compilers from different vendors to compile my program. It seems that recently, due to a misconfiguration, library conflict or my ignorance, with one of the compilers I am having trouble related to libuwind.so, which, to my knowledge, deals with the intricacies of unwinding the stack upon an exception. Executables compiled with this compiler crash with a SEGV after throw(), never...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10045
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7409
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5299
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.