Visual Studio for Mac? MonoDevelop is your weapon

Let me first point out that I don’t like MonoDevelop; a lot of mono based projects and products like Unity still rely on the old 2.8.X version of mono which isn’t the best IDE. I have almost no experience with 3.X but from what i have heard it has become a decent IDE.

However, it is still a solid and good alternative. What is even better, is that it keeps it’s format as close as possible to Visual Studio so any project that you start in MonoDevelop can be opened and worked on in Visual Studio. I am a .NET programmer who find’s himself using a Mac from time to time. What is great is that I can run my projects on a Mac too! For instance, I can build an ASPX application on my Mac!

Mono is a .NET assembly parser; in other words, it replaces the .NET components with ones that can run on other platforms. My understanding is that it in itself is a compiler as well (correct me if I am wrong)

There are limitations to this. Mono is not a Microsoft project. Some say it is slow, some say it has a lot of bugs. In my experience it has not presented me with any issues. From what I understand it has become reliable enough that products like Unity use it to compile game scripts.

Anyways, head over to MonoDevelop and check it out!

Side Note: One reason why the Mono project is so popular is because it lets you port your applications to devices that .NET is not available without making huge changes to your code. For instance MonoGame allows you to port your game to almost any phone/platform out there!


Flipping a Boolean

This is a very quick post but something i see from time to time. Sometimes I run into code like this:

if (someBool == false)
      someBool = true;
      someBool = false;

which works, but it looks ugly and clutters up your code. The easier way to do something like this, is to simply

someBool = !someBool;

The reason for this is simple. What is “Not false”? True. What is “Not True”. False. I am going to guess that there are some performance benefits to using this syntax but I have no research to back that up. Enjoy!

Using The Main(string[] args) Better

I have recently started a college class on Java. It haven’t worked with it in a while and thought maybe its a good choice as the last elective I have left to do. One thing I noticed is that a lot of the assignments and examples don’t mind if you cram your code into the

Main(string[] args) { [...] }

which is fine for those just beginning programming. For a lot of people just making code work is already a god send. However, I cannot help but point out that this is a fairly bad practice for a few reasons:

  • Any class scope variables have to be static
  • All functions have to be static
  • You have to initialize all your variables inside of the main function. Not a good practice.

This is not a very good thing because this is a pitfall for memory management. A program NEEDS to have a static entry point, but this does not mean that you need to wrap your code around it. If everything is static (which is something students LOVE to abuse), then the only time your memory gets cleared is when your function variables go out of scope and/or when the program exits. This is a bad coding practice which makes it very difficult to write optimized applications.

So what do I do?

You don’t have to do much. Simply create a non-static class and call it “Main” or any name you would like to give it. Then simply create a new instance of the variable inside the main and call a start function. Very simple! Let me show you an example:

     public class Main 
          //Now your class variables don't have to be static
          int myInt;

          public Main()
              myInt = 0;
              //Your variables initialization here

          public void start()
          //Put your code here!

and so your static main now looks like this!

public static void main(String[] args) {
      Main main = new Main();

Should I Teach This?

I started Java a about 6 years ago and for a very long time I did not understand how to structure code in an easy way. This concept might be a little bit confusing for students, but it will clean up their code. Students starting Java without coding experience still don’t understand what static variables are (and why you should avoid them), so this will help them avoid the pitfalls of “Well everything is static ill just make mine static too!”. It removes an extra element for something that is already somewhat confusing for many!

Closing Notes

        This helps exit your application better

Its not quite faster or “better” in the sense of exiting, but it nests your code in such a way where you know when your application is exiting. The only time your code will go beyond the “main.start()” is when it is exiting or switching states. This is extremely useful if you want to do some processing right before exiting.