15.04.2018 Views

programming-for-dummies

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

“Curly Bracket” Languages 67<br />

C# advantages<br />

C# has a couple advantages over languages such as C, C++, and even Java.<br />

Book I<br />

Chapter 3<br />

Object oriented<br />

One main advantage of C# over C++ is that C# is a true object-oriented<br />

<strong>programming</strong> language, so you have to use object-oriented <strong>programming</strong> to<br />

write a program in C#.<br />

Forcing you to use only object-oriented <strong>programming</strong> techniques might seem<br />

like a drawback until you realize that C++ is a hybrid language that lets you<br />

choose whether to use object-oriented <strong>programming</strong>. Although C++ gives<br />

you, the programmer, more flexibility, C++ programs can also be a mish-mash<br />

of structured <strong>programming</strong> mingled in with object-oriented <strong>programming</strong>.<br />

Types of<br />

Programming<br />

Languages<br />

Trying to decipher such a mix of <strong>programming</strong> techniques can be confusing.<br />

By <strong>for</strong>cing all programmers to use object-oriented <strong>programming</strong> (and isolate<br />

their structured <strong>programming</strong> techniques only inside objects), C# programs<br />

can be much easier to understand and modify.<br />

The pros and cons of type-safe languages<br />

So why isn’t every <strong>programming</strong> language typesafe?<br />

Good question; here are two reasons:<br />

Creating a type-safe language means more<br />

work to create a compiler that can examine<br />

an entire program and check to make<br />

sure data types (such as numbers and<br />

text) aren’t getting changed around<br />

unexpectedly. This translates into a slower<br />

and more complicated compiler, which is<br />

more work <strong>for</strong> the programmers who have<br />

to create the compiler in the first place.<br />

Type-safe languages can be restrictive, like<br />

trying to ride a motorcycle in a padded suit.<br />

The padded suit may protect you, but it also<br />

restricts your movement. Similarly, by not<br />

checking that data types remain consistent<br />

throughout a program, other languages give<br />

the programmer more freedom.<br />

Use this freedom wisely and you can create<br />

programs without the nuisance of type-safe<br />

checking, which can feel like having your<br />

mom staring over your shoulder every time<br />

you browse the Internet. Use this freedom<br />

poorly and you’ll wind up writing a program<br />

that crashes the computer.<br />

Although non-type-safe languages are popular,<br />

the growing trend is to use type-safe languages<br />

that protect the programmer from writing programs<br />

that can mess up its data and crash the<br />

entire computer. Java, C#, and other languages,<br />

such as Pascal, are considered type-safe<br />

languages.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!