Yesterday's passion revisited

I used to program in Pascal - a bunch of programs - thousands and thousands of lines of code sitting around. Uhhhh....it was Turbo 5. Instead of trying to learn a new IDE as well as, say, C#, I thought would "port" my old Pascal code to Windows. Suggestions? Comments? Criticisms? Free Pascal? Delphi? C#? Thank you, in advance, for your time and effort!

Comments

  • I stayed with DOS (Turbo Pascal 7) for about a decade and then finally played with some Visual Basic, Delphi & now C#/.NET
    Visual Basic was very good to help with the transition to windows programming and some of the different methods of thinking. Delphi was definately more powerful, but I've now turned to Visual Studio .NET.
    I find the IDE very helpful and home version is free. Also, you can then get the XNA add-on (for making Windows & XBox360 games). It's like DirectX stuff, but easier.

    I found the most difficult step in switching was trying to figure out what I needed to include to use a certain function. With pascal, you just always included CRT, DOS and away you'd go.

    Anyways, get Visual Studio Express from Microsoft (yes, it's free... something seems wrong here) and learn that. C/C++/C# syntax is a bit different from pascals' so it will take some time to learn at the start. Just google sample code/etc and use the message boards.
  • Thanks for your insight. Seems you went the path I have been thinking of... I have C# Express as well as VS2008. Syntax is syntax. I don't have much a problem with that. The USING statements vs. Unit includes - there should be a reference to assist with that learning curve.

    Another question? I am having a logic problem, though. Is there a reference that can clarify/compare the differences between procedures and functions with the vernacular of classes and uses of public, global, etc?

    Thanks, again, for your help!

  • : Thanks for your insight. Seems you went the path I have been
    : thinking of... I have C# Express as well as VS2008. Syntax is
    : syntax. I don't have much a problem with that. The USING
    : statements vs. Unit includes - there should be a reference to assist
    : with that learning curve.

    Help Files. But seriously, it's more of a repetitive learning game I think.

    : Another question? I am having a logic problem, though. Is there a
    : reference that can clarify/compare the differences between
    : procedures and functions with the vernacular of classes and uses of
    : public, global, etc?

    Hmmm. Vernacular? Had to look that one up, it's not in my standard word use. lol. Still not totally sure of the definition although I read Webster's definition.
    Anyways, not sure where you are lost as to Procedures/Functions. Pascal had Procedures, which could take input vales, but returned noting, and it had Functions that could take input values and would return something. C# on the other hand doesn't use name declarations such as PROCEDURE/FUNCTION, instead it just figures it out by what is returned.
    A procedure is declared like so:
    [code]
    void printResults( string textToShow )
    {
    MessageBox.Show(textToShow);

    // Doesn't need to be here, but if needed in a procedure can be called.
    // Notice there is no value passed to return as the procedure returns no value (VOID).
    return;
    }
    [/code]

    The same function would be declared like so:
    [code]
    int printResults( string textToShow )
    {
    MessageBox.Show(textToShow);

    // A function must call return.
    // Notice the value passed to return
    return 26;
    }
    [/code]

    I don't think GLOBAL even exists, but because everthing is in a class in C#, everything must be public or private (if undeclared it has set defaults)
    Any Procedures/Functions in the class have access to all variables and other functions in that class, but if a second class wants to access either a function or a variable in the first class, they must be declared as public.
    Also, they can be declared static as well, which means that variable/function will be the same no matter how many of those classes are created. I am still new to C#, so writing code from head isn't good. Here's the basic concept though:
    [code]
    class myHockeyGame
    {
    class playerInfo
    {
    public int number;
    public string name;
    [italic]// speed is a private variable so others can't change it[/italic]
    private int speed;

    [italic]// Constructor allows speed to be set when player created[/italic]
    void playerInfo(int setSpeed)
    {
    speed = setSpeed;
    }
    public int getSpeed()
    {
    return speed;
    }
    }

    class teamInfo
    {
    public string name;
    public [b]static[/b] string homeTown;
    public playerInfo[] players;
    }

    // Create a team
    teamInfo myTeam = new teamInfo();
    myTeam.name = "Canucks";
    myTeam.homeTown = "Vancouver";

    // Create a player
    playerInfo myPlayer = new playerInfo(80);
    myPlayer.number = 1;
    myPlayer.name = "Roberto";

    playerInfo[] myTeam.playerInfo = new playerInfo[1];
    myTeam.playerInfo[0] = myPlayer;

    // Create a second team
    teamInfo myTeam2 = new teamInfo();
    myTeam2.name = "Kings";
    myTeam2.homeTown = "L.A.";
    }
    [/code]

    This all looks okay (other than mistakes), except because we declared [b]homeTown[/b] as static, myTeam.homeTown will now be "L.A." and not "Vancouver".
    Obviously you wouldn't use it in a situation like this, but there are times when you need a class to have a sort of "global" variable.

    Hope this helps a bit. If I'm way off, just give me a slap.
  • Really do appreciate the explanations. I use "vernacular" as "vocabulary/slang",i.e., programmer's lingo. Hope that helps. ;)

    Not sure yet how static works...you mean that team Canucks is now from LA?

    As for speed being declared private so it can't be changed by the user... I would just not create the option for the user to change it. Viola! Why require the declaration of something that is unnecessary? OK - what am I missing? :]

    (I agree with you not posting the student's solution to his exam. Good work!)

    < Steve >
  • : Really do appreciate the explanations. I use "vernacular" as
    : "vocabulary/slang",i.e., programmer's lingo. Hope that helps. ;)
    :
    : Not sure yet how static works...you mean that team Canucks is now
    : from LA?

    Kinda. You cannot just use a CLASS. It is the pascal equivilent of TYPE, therefore in order to use it you have to do a variable declaration. In pascal, a record is used like this:
    [code]
    TYPE
    person = record
    Name : String;
    Age : Byte;
    Gender : Boolean;
    Species : String;
    End;

    VAR
    Me : person;
    You : person;
    coworkers : Array[1..5] Of person;
    [/code]
    in c# the same would be:
    [code]
    namespace myProgram
    {
    public class person
    {
    public string Name;
    public int Age;
    public bool Gender;
    public static string Species;
    }

    person Me = new person();
    person You = new person();
    person[] coworkers[5]();
    }
    [/code]
    As you can see I declared Species as STATIC since all these people are human, it is shared. Also, static variables can be accessed from other units without first declaring the class.
    The [green]GREEN[/green] lines below are okay, the [red]RED[/red] lines would result in an error.
    [code]
    [green]myProgram.person.Species = "Human";[/green]
    [red]myProgram.person.Name = "Ralph";[/red]
    [red]myProgram.person.Age = 50;[/red]

    [green]myProgram.Me.Name = "Phat Nat";[/green]
    [blue]myProgram.Me.Species = "Human";[/blue]

    [green]myProgram.You.Name = "Steve";[/green]
    [green]myProgram.You.Age = 30;[/green]
    [/code]
    The [blue]BLUE[/blue] line is right, but will change the Species for all of the variables.


    : As for speed being declared private so it can't be changed by the
    : user... I would just not create the option for the user to change
    : it. Viola! Why require the declaration of something that is
    : unnecessary? OK - what am I missing? :]

    You declare stuff private when you need your program to use a variable, but you don't want the chance of an external unit or procedure changing it.
    Taking the hockey game example back, you need your player to have stats that can be read, but if the stats could be changed, people could cheat and max out their stats.
    Therefore at times you need to be able to have variables to store stuff "secretly". Also, if you create a class for others to use that has 100 variables, of which 75 are only used internally, why would you want the user to have to look through 100 variables for the 25 they can actually use? In this case again, make them private.


    Sorry if I'm not explaining it well, but it's hard to think up examples off the top of my head. When you're programming you run into situations where you say, "yeah that needs to be statiic" or "This had better be private".
  • I'm a little older than 30...but thanks! I do know that sometimes it is easier to code than to explain. You're doing well, thanks!

    I noticed that namespace was used as a "descriptor" of the class person,i.e., namespace."person".name. Interesting. I'm getting into it more.

    Do appreciate your help!!


    I'm using VS8. If you are, too... Is there a way to save my configurations so the default form always comes up with MY selected defaults and not Bill Gates'?

    < Steve >

  • : I noticed that namespace was used as a "descriptor" of the class
    : person,i.e., namespace."person".name. Interesting. I'm getting
    : into it more.

    Every "Unit" needs a name. NAMESPACE is like Pascal's PROGRAM/UNIT declaration at the program top.


    : I'm using VS8. If you are, too... Is there a way to save my
    : configurations so the default form always comes up with MY selected
    : defaults and not Bill Gates'?

    Not sure how to save the defaults completely. I actually haven't been programming in c# that long. I just always load a workspace which reloads your settings.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion