Go Back   openSUSE Forums > Archives > SF Archives > ARCHIVES - Software
Forums FAQ Members List Search Today's Posts Mark Forums Read


ARCHIVES - Software Questions about use, installation, or configuration of software running on SUSE Linux

 
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-Oct-2004, 08:31
littleccguy
Guest
 
Posts: n/a
Default

We recently started working with SETS in Pascal in class. I test my code using both Kdevelop and FPC in a terminal on SuSE 9.1. No matter how I try to create the set, if I use a negative number both compilers error out. If I do the same thing in Dev_Pascal under Windows, it works fine. :unsure:
  #2 (permalink)  
Old 06-Oct-2004, 15:19
hvengel
Guest
 
Posts: n/a
Default

In Pascal sets can only contain ordinals. By definition ordinals can not be negitive as they are represented internaly by unsigned 8 bet values. The fact that it works with a particular compiler is just an indication that that compiler is non-standard.

Since sets can be any ordinal this opens up the possibility to define some very useful constructs. For example we might define the following:

type
Day = (Monday, Tuesday, Wednesday, Thursday, Friday, Saterday, Sunday); (* define new ordinal *)
WeekDayType = set of Monday..Friday; (* define set of new ordinals*)
WeekEndType = set of Saterday..Sunday;

var
WeekDay : WeekDayType;
WeekEnd : WeekEndType;

Now we have defined a data type that contains a useful logical contruct for the days of the week. This will allow us to make the code very readable and easy to maintain yet allow the compiler to generate very good executable code. In addition, the Pascal compiler can enforce strick type checking. Internaly the values used will be positive 8 bit integers from 0 (Monday) through 6 (Sunday). But because of strict type checking the following is not a legal statements:

WeekDay := [Saterday, Sunday]; (* Saterday and Sunday are not of type WeekDayType *)
WeekDay := [1..3]; (* 1,2 and 3 are not of type WeekDayType *)

But the following are legal:

WeekDay := [Monday];
WeekDay := [Tuesday..Thrusday];
WeekDay := [WeekDayType(1)]; (* explicit type conversion (cast) WeekDayType(1) = Monday and ORD(Monday) = 1 *)

The max number of ordinal values in any set is limited to 256 (8 bits).

Hope this helps. I have not worked in Pascal for about 18 years so my syntax may not be totaly correct. So please cut me some slack if that is the case.
  #3 (permalink)  
Old 06-Oct-2004, 16:43
littleccguy
Guest
 
Posts: n/a
Default

Thank you very much for your reply. I agree/understand everything you explained. It lines up with the lessons we have gone through as well. Here is what is confusing:

ordinal types are either integer, char, or boolean right? the base type of sets is ordinal. Integers are {...,-3,-2,-1,0,1,2,3,...}.

It's a little maddening.

Anyway, I got the homework completed and turned in on time, and your feedback was great.

Thanks
  #4 (permalink)  
Old 07-Oct-2004, 11:47
hvengel
Guest
 
Posts: n/a
Default

In Pascal integers are not ordinal types. Ordinals are things that can be represented by an UNSIGNED 8 bit value. Integers are by definition signed. In addition ordinals can be things other than unsigned 8 bit numbers, char and booleans. As you can see in my example ordinals can be defined by a programmer that represent logical contrustructs that are not numaric, char or boolean in nature (Days). The reason that I used that example was to show the extensibility of the underlying constructs and to make it clear that ordinals were things that you could count - as in count on your fingers and you always have 0 or more fingers, you never have a negative number of fingers.

One other lesson you learned from this centers around standards. If you use a compiler that does not follow accepted standards then YOU, the programmer, must understand what the standards are and then only use the non-standard features with a full understanding of the implications. Those implications in this case are in the difficulty in porting to other systems/compilers. As you found out you had to rewite your code to use a more standard compiler which is a real PITA even in the case of a small program. So the general rule that most programmers will follow when using a compiler with non-standard features is to not use those features or at the very least to carefully isolate where those features are used so that a port to some other system/compiler will only require the rewrite of small isolated parts of the system. Keep in mind that real world systems can have hundreds of thousands or even millions of lines of code and if a port requires a significant rewrite it can be VERY expensive. I have worked on many systems that were over one hundred thousand lines of code and the largest I have worked on had 9.2 million lines. The 9.2 million line program was slightly over 50% assembly code and was not considered portable but all of the other systems were written to very tight standards using high level languages and would have been fairly easy to port if needed.
  #5 (permalink)  
Old 07-Oct-2004, 22:02
emry
Guest
 
Posts: n/a
Default

I can't believe Pascal is still used let alone taught. I used it back when the 1987 release was done in some engineering classes, but most of us forgot it as quick as we learned it.
  #6 (permalink)  
Old 08-Oct-2004, 13:56
hvengel
Guest
 
Posts: n/a
Default

There are many schools that still use Pascal as a teaching language and there are systems that are still in use that are written in Pascal. And some programmers still actively use Pascal because they like it.

The reason that it is still being used as a teaching language is that it is fairly simple to understand, is strictly typed, readable and helps new programmers develop good habits. C, C++ and Java are also used as teaching languages these days but I personaly do not think these are good languages to start students out with. They have obtuse difficult to read syntax and do not have strict typing. The first makes it hard for a student new to programing to understand what is going on and the second allows new programmers to develop very bad habits. Neither of these are good characteristics in a teaching language.

Let me just add that real world experience with younger programmers that learned using C, C++ and Java does not contradict the above statements. Also programmers that learn programming with a strictly typed language carry thier good programming habits over to languages like C, C++ and Java and generaly write cleaner, easier to maintain code in these languages then do those that started out in C, C++ or Java.

The newer Pascal variants such as Modula-2 and Ada are also good teaching languages in many ways but with OO features, more modularity and more generality that make them some what harder to understand for a new programmer. Typing is also stricker than in Pascal. Particularly Ada which is so strickly typed that Pascal programmers need a little time to adjust to how strict the typing rules are. Both languages are used in some schools to introduce new programming students to the subject.

Ada, of course, is the language used for all DOD systems and was the worlds first standardized OO language (ISO & ANSI 1995). Modula-2 was designed by the same man that designed Pascal, Niklaus Wirth, in the late 1970s as a follow on to Pascal which he designed around 1969. He intended it to be more modular, exstensible and generalized than Pascal. It is a very compact language with less than 2 dozen reservered words but it is also a very rich, powerful and expressive programming language.

If I were responsible for teaching new programmers I would probably start new students out using Ada since it is the most cabable of the Algol - Pascal - Modula-2 - Ada language line, has a natural path to OO and also the most widely used. Number 2 on my list would be Modula-2 and third would be Pascal. But if it were between Pascal and C, C++ or Java I would not even think twice about it as Pascal is a far better language for starting new programmers than C, C++ or Java.

By the way all of these languages other than Algol, which is truely obolete, have GCC fronts ends available. C, C++, Java and Ada are production level and are part of the standard GCC distribution along with FORTRAN 77 and Objective C (for Mac users). The GCC Pascal front end is pre-release (post Beta) and very stable and the Modula-2 front end is at this time a fairly stable beta. Both Pascal and Modula-2 are GNU projects and when these front ends are production quality will be part of the standard GCC distribution.
  #7 (permalink)  
Old 08-Oct-2004, 14:22
kastorff
Guest
 
Posts: n/a
Default

Man, these posts bring back memories.
  #8 (permalink)  
Old 19-Oct-2004, 15:28
littleccguy
Guest
 
Posts: n/a
Default

Thanks to all for replying to this thread.

hvengel - you hit the nail on the head. Teacher I had was great. He was personable and has a background that includes a vast number of years writing code. The things he kept emphasizing to us was learn and remember the basics, keep the code looking clean and organized so it is easy to follow, and document, document, document.

I did quite well for someone who has very little experience in programming. It was worth the time.

So now I am off to start my C Programming class. Wish me luck and I'll talk to all of you later.

Oh yeah - thanks for being there.

I'm out B)
 

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




 

Search Engine Friendly URLs by vBSEO 3.3.0 RC2