Jump to content

modern languages - working with files


Recommended Posts

I want to learn a modern OO language. I have bought a few of the highly-rated java books, but recently I have read that python may be a better choice to learn on. (there may have been a thread regarding this - several months ago...)

 

I am used to working with permanant data files - usually indexed, or ISAM they were called. You would add new records to the file, or update existing records, or whatever you wanted.

 

To create the file, you would define the record length, and all the fields and their types and lengths. And define the key field.

 

I'm confused when looking at python samples that read or write to files. It might read the first "200" bytes, or it might read "one" line...

 

Does the "one line" mean like an entire record? And are records now "variable length"? I think they used to be fixed-length. Haven't written a cobol program since the early 90s.

 

To learn a new language, I may want to do a project - such as something useful to me - like say to write some program that keeps track of something - in a permanant file - like a record collection (record albums). Or something like that.

 

I've been spending all my time learning linux, but now that I have a nice new machine and FC2 up and going on it, I'd like to get going on an OO language.

Link to comment
Share on other sites

I use python myself and the way you describe COBOL working with files is a very cool way. It reminds me more of a database of some sort.

 

By one line, it literally means, one line of the file. One byte is one character in this case. Comparing it to the COBOL way you describe, it seems very rudimentary.

 

If you are interested in working with a more COBOL way of working, take a look at these standard modules:

 

http://python.org/doc/2.3.4/lib/module-dbm.html

 

This one seems better.

http://python.org/doc/2.3.4/lib/module-gdbm.html

 

And some more information here:

http://python.org/topics/database/

 

I hope this helps, i havent had any experience with databases.

 

iphitus

Link to comment
Share on other sites

In general languages such as python tend to deal with a plain text file. The older languages such as COBOL, Fortran and C usually performed I/O on binary data files so the fundamentals of dealing with files is completley different.

 

Scripting languages (like python and perl) are currently very popular and are often used in writing front ends to config files and most package managers tend to rely on them. I tend to prefer traditional languages as they suit my needs (numerical computation) much better. If you simply want to mess about with text files (such as the CD database you mention) you should probably look at the scripting languages.

 

HTH in some way

Link to comment
Share on other sites

I guess it does sound more like a database thing. In cobol, I would have a program that you could enter, say, an item number on your screen, and then the program would check the file and if the item # was found, the program would display the info to your screen (you also designed which fields would display and what positions on the screen).

 

Guess nothing learned in my younger days is any good anymore. I kind of regret not learning any OO stuff 10 years ago or so - like C or something.

 

Now when I look at a Java program it looks like greek. Some of you older guys might know that when you read a cobol program - its like reading a novel...

 

If so and so thing is true, then perform paragraph X  

 

Now, I do know what bits and bytes are - they had those back in the 80s too ;)

and I also know how For / Next, Do While, If Else, and all that stuff works. We had that stuff back then also.

 

In cobol, I'm used to thinking in tems of what was called "Structured Programming". Where you would have like a Main program block, and in there you would Perform various other Paragraphs based on what you wanted to do. These other Paragraphs were just other blocks of code in the same program. Or you could also Call external Subroutines that were "outside" of your program.

 

From what I can tell from reading my Java books, it looks like the above stuff is now done with Methods.

 

Like I said above, I know the mechanics of programming (loops and stuff like that). Its just the new ways and syntax of doing stuff that is confusing.

Link to comment
Share on other sites

I kind of regret not learning any OO stuff 10 years ago or so - like C or something.

 

C isn't actually an OO language, but C++ is.

 

I'm also used to structured methods of programming and still use it in Fortran and C codes. I'd assume C++ is also like this but I've never got round to learning it - I have an aversion to OOp - burned by UML!!

Link to comment
Share on other sites

oh, well - I knew what UML stands for, I just didn't know exactly you were meaning by what you said

 

Well, the world is going to pictures for everything right ? Like when I go to the gas pump, the "instructions" on the pump are just 4 pictures I think. Guy removing the handle, guy flipping up the lever, guy sticking the nozzle in his gas tank, guy returning the nozzle and flipping down the lever.

 

I don't see how you could program anything by drawing pictures. You mean its like a preliminary design step before the actual coding ?

Link to comment
Share on other sites

The documentation even encourages python'esqe jokes :)

 

http://python.org/doc/2.3.4/tut/node3.html

 

By the way, the language is named after the BBC show ``Monty Python's Flying Circus'' and has nothing to do with nasty reptiles. Making references to Monty Python skits in documentation is not only allowed, it is encouraged!
Link to comment
Share on other sites

I haven't programmed in python yet ..but I want to learn. I have pogrammed in java and C++ though.

 

You have more lover-level access to files it seems (likes bits, ... liek menionned). You could create an object record however and make a constructor (thing that initialises an object) that reads data from a file from example. You could then build an object "Recordsfile" or so that let's you handle a file that contains records using a defined interface. You could make a base class Record and define the structure of teh record in other classes that use Record as baseclass for example . So you could maybe use different recordstypes for a same Recordsfile-object, but use the same base-methods/functions to access all type of records as far as that is possible... I suppose this could be done .. haven't tried it myself I think though.

 

 

I hope I'm not confusing you ... You can make you entire classes (class=object) in UML first and specify the dependencies, variables, ... in/of it and then let the baseic code be autogenerated from the UML.

 

The real implementation of the functions has to be still done by hand. UML can be handy (to my opinion) to see what kind of problems you can encounter building you code, design your classes better..withou messing with real code and having a good overview of your classes. It can be a step in designing your program...

Edited by Michel
Link to comment
Share on other sites

I'm used to thinking of working with files in that each record of a file is a fixed length, and you read whatever record you are interested in - could be the first record, or could be somewhere in the middle of the file... so it would be an indexed file.

 

While reading java or python books, it looks like files are just lines of text with /n at the end. Guess you have to seek the spot you want to read, if your not reading sequentially.

 

The books I have browsed thru mostly agree that python is a easier language to learn. They say a program in java would be alot smaller in python.

 

For what I want to do - set up my record collection (the 12" vinyl things - not CDs) on my computer. I would have input screens to input new albums that I buy at collector conventions, or I could look up info on existing albums. I previously had my entire collection in an Excel spreadsheet, which has now been lost... my fault.

 

I took a course in VB6 last year, and got an easy A in it. Maybe that would do what I want. Even though I don't really want to learn any more VB. Would rather do the same thing with java or python - if they do stuff like that.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...