C#: Generic swap functions

This entry is part 70 of 71 in the series C#

Generic swap functions

namespace Test
{
	class Program
	{
		
		public static void Swap<T> (T a, T b)
		{
			var temp = a;
			a = b;
			b = temp;
		}

		public static void Swap<T> (ref T a, ref T b)
		{
			var temp = a;
			a = b;
			b = temp;
		}

		public static void SwapValue (SwapTest a, SwapTest b)
		{
			var temp = a.Value;
			a.Value = b.Value;
			b.Value = temp;
		}

		public class SwapTest
		{
			public string Value { get; set; }
		}

		static void Main ()
		{
			var a = new SwapTest { Value = "a" };
			var b = new SwapTest { Value = "b" };
			Swap (a, b);
			Console.WriteLine ("Value a: " + a.Value + " |  Value b: " + b.Value); 
			//output: Value a : a | Value b : b  

			a = new SwapTest { Value = "a" };
			b = new SwapTest { Value = "b" };
			Swap (ref a, ref b);
			Console.WriteLine ("Ref Value a: " + a.Value + " |  Ref Value b: " + b.Value); 
			//output: Ref Value a : b | Ref Value b : a 

			a = new SwapTest { Value = "a" };
			b = new SwapTest { Value = "b" };
			SwapValue (a, b);
			Console.WriteLine ("Swap Value a: " + a.Value + " |  Swap Value b: " + b.Value); 
			//output: Swap Value a : b | Swap Value b : a 
			Console.Read ();
		}
	}
}

swap

C++: Using Netbeans IDE

This entry is part 37 of 61 in the series C++

We divert a bit and we will write some of our code with Netbeans IDE instead of MS Visual Studio.

Code completion and refactoring are available in Netbeans and if you have like to use  refactoring in Visual Studio, you will have to use the professional edition and download a refactoring plugin.

Netbeans is dynamic and it supports a variety of C++ compilers such as Cygwin and MinGW.  For our examples, we will use Cygwin compiler.

We will go through the process of installing the Cygwin compiler in the next 2 posts making Cygwin compiler to be able to work with Netbeans IDE.

 

C#: Intro and cross-platform development

This entry is part 1 of 71 in the series C#

C# has been around for more than a decade now.

Microsoft developed C# as an answer to Java.  Java is known for its write once, run anywhere paradigm.

With C#, and with the open source .Net framework, you can indeed run C# code in Mac and Linux.

To run C# program in other platforms such as Mac and Linux, you need the Mono software platform.

Mono is an open source, cross-platform implementation of C#.  The CLR or the Common Language Runtime, an interpreter, is binary compatible with Microsoft.NET

Mono is a software platform designed to allow developers to easily create cross-platform applications. It is an open source implementation of Microsoft’s .Net Framework based on the ECMA standards for C# and the Common Language Runtime.

You can for example, develop iOS apps using C# by using the Xamarin software development tools.

Posted in

Javascript vs PHP, which to start learning first for beginners?

Javascript has been getting very popular in the past 2 years mainly because together with HTML5, you can create iPhone or Android apps.

Though it is known that in terms of speed, Javascript will never be able to catch up with native apps, there are still many applications that are suitable for developing with Javascript.

If you delve into these 2 languages, you would be surprised how different they are.  You can say C and Java are very similar but you can’t say PHP and Javascript are similar.

What makes PHP so popular? It’s the simple reason that PHP is server side and the code written is hidden in the server.

If you are a new web programmer, I strongly suggest that you start with Javascript first.  Javascript has a better separation between the script and HTML making it a lot more easy to code.

When you first learn about Javascript, you do not have to worry about HTML or CSS.  You can learn it as if you are writing in C.  However, when you are writing PHP, you need to put the HTML into the code making it really confusing for the beginners.