Close

Some basics constructs

A project log for Soma

Soma is a project that has been close to my heart for a long time. A "real" object-oriented and low-level programming language.

damfledamfle 12/02/2018 at 19:050 Comments

This is a draft that I publish. It will be edited soon. It is there to make you wait while I rearrange my notes ;)

Lets get started and look at this piece of dumb C# code to highlight some basics constructs.

The constructs will be detailed in other projects logs. We're just defining some syntax here.

using System;

namespace SampleApp
{
    public class Program
    {
        private int op;
        private int square;

        public Program(int op = 0)
        {
            this.op = op;

            Console.WriteLine("Hi, I'm a program and will do a square calculation of " + this.op.ToString());

            return;
        }

        public void doSquare()
        {
            this.square = this.op * this.op;

            return;
        }

        static void Main(string[] args)
        {
            int inputOp = 0;

            if (args.Length < 1)
            {
                Console.WriteLine("Error you must specify an argument !");
                return;
            }

            try
            {
                inputOp = int.Parse(args[0]);

                Program theProgram = new Program(inputOp);
                theProgram.doSquare();

                Console.WriteLine("The square of " + theProgram.Op.ToString() + " is " + theProgram.Square.ToString());
            }
            catch (Exception e)
            {
                Console.WriteLine("The argument must be an integer !");
                return;
            }

            return;
        }

    }
}

So. We do have a dumb code who's doing a dumb square calculation. Lets cut it into small parts.

using System;

In C# is a way to import externals classes or packages. We do need this in your language. Code must be modulable.

namespace SampleApp

Help to keep things where they should be. But we won't talk about this for now.

public class Program

 Hmm. We may have some things to keep here.

private int op;
private int square;

Next. Here are some members of the class. We do have :

Discussions