Table of Contents
A. The Beginner's Creed
B. The Fluff Behind C#, Visual Studio, and .NET
C. First Application: Basic UI in C# and Visual Studio
A). Learning to Learn
There's a hidden gem in one of the forewords to Gloria P. Flores' Learning to Learn and the Navigation of Moods: a Beginner's Creed written by computer operating systems insturctor Peter J. Denning.
While I was going to give a summary of the book itself, seeing as I haven't finished it, I thought I'd just share this. Bonus points for reading it every day for a week.
Peter J. Denning's The Beginner's Creed
I am a beginner.
I am entering a new game about which I know nothing.
I do not yet know how to move in this game.
I see many other people playing in this game now.
This game has gone on for many years prior to my arrival.
I am a new recruit arriving here for the first time.
I see value to me in learning to navigate in this domain.
There is much for me to learn:
The basic terminology
The basic rules
The basic moves of action
The basic strategies
While I am learning these things I may feel various negative reactions:
Overwhelmed at how much there is to learn
Insecure that I do not know what to do
Inadequate that I lack the capacity to do this
Frustrated and discouraged that my progress is so slow
Angry that I have been given insufficient guidance
Anxious that I will never perform up to expectations on which my career depends
Embarrassed that everyone can see my mistakes
But these moods are part of being a beginner. It does not serve my goal and ambition to dwell in them. Instead,
If I make a mistake, I will ask what lessons does this teach.
If I make a discovery, I will celebrate my aha! moment.
If I feel alone, I will remember that I have many friends ready to help.
If I am stuck, I will ask for help from my teachers.
Over time, I will make fewer mistakes.
I will gain confidence in my abilities.
I will need less guidance for my teachers and friends.
I will gain familiarity with the game.
I will be able to to have intelligent conversations with others in the game.
I will not cause breakdowns for promises that I lack the competence to keep.
I have an ambition to become competent, perhaps even proficient or expert in this game. But for now,
I am a beginner.
B). What is Visual Studio? C#? The .NET Framework?
You should know--the majority of this article is background information. Foundational is the better word. It might seem like a lot of set-up for a little outcome, but we're talking here about concepts that we will need to take as given when we go to work on future projects.
It doesn't hurt to spend a good portion of our time familiarizing ourselves with these terms.
So my practicum assignment was to make a basic UI (User Interface) form in Visual Studio.
Here's some examples of UI:
Visual Studio is an IDE (integrated developer environment), which is to programmers what Microsoft Word is to writers. It organizes, corrects, and sometimes even auto-completes snippets of code, provides information on what does what, comes with ready-made templates, and takes care of your files.
IDEs usually come with frameworks. Our IDE, Visual Studio, uses what's called the .NET Framework.
First of all, what IS a software framework?
Stack Overflow's Neha Choudhary gives a great concrete analogy:
"If I told you to cut a piece of paper with dimensions 5m by 5m, then surely you would do that. But suppose I ask you to cut 1000 pieces of paper of the same dimensions. In this case, you won't do the measuring 1000 times; obviously, you would make a frame of 5m by 5m, and then with the help of it you would be able to cut 1000 pieces of paper in less time. So, what you did was make a framework which would do a specific type of task. Instead of performing the same type of task again and again for the same type of applications, you create a framework having all those facilities together in one nice packet, hence providing the abstraction for your application and more importantly many applications."
And here's your more standard dictionary definition from Techopedia:
"Frameworks take the form of libraries, where a well-defined application program interface (API) is reusable anywhere within the software under development. The purpose of software framework is to simplify the development environment, allowing developers to dedicate their efforts to the project requirements, rather than dealing with the framework’s mundane, repetitive functions and libraries."
So, a framework makes it so we don't have to keep reinventing the wheel.
There were two more terms nested in there that are important to go over: library and API.
In programming, a library is a collection that stores frequently-used routines so we can easily access them. Hey, that sounds a lot like a framework. Well, a framework is a type of library. (I'm finding a lot of cross-pollination in programming terms--and YES, it IS annoying that most of the definitions have about five unknown definitions within their definition).
An analogy. Let's say we want to program a sandwich, and we have access to a library of sandwich recipes. Well, when we're programming our sandwich, it's not enough to list the ingredients. We also need to give clear instructions, or routines, on where to gather the ingredients and how to put them together.
Now, it would be really tedious if every time we wanted to make a sandwich we had to laboriously explain how to find the bread box, open the bread box, locate the right bread, untie the bread bag, take out only two slices of bread, re-tie the bread bag, put the bread bag back into the bread box, close the bread box, then....
We have a library for that. We just pull up the, say, GatherIngredients() function, and our little program fills in all those steps. We get to focus instead on specifying specifics about the sandwich--pickles or no pickles, light on the mayo, if turkey is available use that if not use salami, while frying bread cut the avocado slices, trim the crusts only if Johnny is asking for a sandwich, etc.
Key Basic .NET/Visual Studio Takeaways
Key Terms: IDE, software framework, library, API, .NET, Visual Studio, C#
C). Notes on Making Basic UI in C# and Visual Studio
Setting Up and Explaining the Fluff
1. Created Windows Form, popped up with Form1.cs and Form1.cs[Design]. You can drag and drop various buttons, text boxes, and input types. However, we still need to alter the code to tell the program what to do with those inputs when they receive feedback from the user (feedback includes clicking or unclicking a checked box, typing in text, etc.).
2. Anything you drag and drop onto the form is added to the Form1.cs file. Visual Studio generates pre-made code and puts them all under a public partial class. What does this mean?
3. Let's look at the code.
Within the curly braces, we’re telling the program what we expect this public Form to do. Well, we want to InitializeComponent(). Those open parentheses are how we tell the program—execute! Think of them as the imperative case in C# programming—a type of punctuation, if you will. The semi-colon ; is the equivalent of a period. Without it, computers can’t even tell it’s a run-on sentence—it just stops short and does a D’oh!
‘InitalizeComponent()’ is a built-in argument. If you scan to the top of the program, you’ll see a long list of lines staring with ‘using.’
These are all the namespaces that this program is using. Within these namespaces, our program can pull from the ready-made functions, arguments, coding pieces already included—no need to define what they do, they are built into the line of code itself. Sweet, right?
Confused by all the periods? While it’s not important to know what ALL of these mean now, we can break down just one example:
Using is a keyword. System is the namespace. Collections is a class within that namespace.
Continue with the library analogy and think of this like a book.
‘System’ is the name of our library. There’s a shelf called ‘Collections’ within that library, and on that shelf, there’s a book called ‘Generic.’ Like the Dewey Decimal System at your local library, the computer knows how to navigate to the specific info you request.
(We could even go further and say in that book there's a specific chapter, and in that specific chapter there's a specific sentence, etc).
So, InitializeComponent() is built into the libraries we are accessing, and allows us to, you guessed it, initialize (prepare) the component (in this case, the Form).
4. Now for all these ‘private void’ things. Notice that there is a private void class for each of the buttons/boxes I dragged onto our Form Design. Visual Studio has set up a basic object for us, but it’s up to us to define that object’s behavior. That behavior will be defined in the curly braces. But what about all that STUFF that comes before the curly braces?
*Public vs. Private. So far we’ve seen public classes, and now we see private classes. When something is public in C#, that means the program at large can access the data within that class. But if a class is private, only that class has access to what is within it. So, all our objects, our buttons, are private void.
*What is void? Void is nothing. Eh? What? I know; what’s the point of declaring nothing? In this case, we’re just declaring that we aren’t returning a value. We don’t need the program to pull up an error just because we haven’t said—”Hey, this is equal to 3, or true, or bananas.” If we executed this code without any behavior written between the curly braces, we’d simply have the Form Design we created. While we couldn’t do anything useful with this form, we at least wouldn’t be thrown back an error.
*Name. ‘Private Void’ is followed by the name (bloodTypeCombo, etc.) we’ve chosen to call our class or object. Simple as that.
*Parentheses and Arguments and Parameters. We mentioned before that the () parentheses imply ‘Execute!’ That’s not the most technically accurate answer, but it’ll do for now. We can actually ‘pass arguments’ and ‘pass parameters’ into these parentheses. It’s what the behavior we code into the curly braces will be referring to.
Parameters are used to pass values or variable references to methods. The parameters of a method get their actual values from the arguments that are specified when the method is invoked.
So, "parameters" refer to names, and "arguments" refer to values bound to those names. (Thanks to Stack Overflow’s Pavel Minaev for this definition).
In this case, we have two parameters: sender and e.
Where The Actual Coding Begins...
5. Here’s where I learned to define the behavior—I.E. where the actual coding began.
But I'm only going to explain one part in-depth.
Now, let's break this down:
Overall Summary: This class defines the drop-down combo box that allows the user to pick their blood type, from A, B, AB, or O. It creates a string called 'bloodType' that gets its value from the user's input.
Breaking It Down:
Key Visual Studio Window Form Takeaways
Studying programming is like getting on a never ending staircase--each step has steps popping out of those steps popping out of those steps popping out of those steps....
What I'm trying to say is that it's easy to feel like you need to understand a million things in order to understand one thing. And don't get me wrong, going for depth is the surest way to understanding something intuitively and being able to use it correctly and quickly.
However, for all that we covered today, there are really just four basic moves we made in creating a C# application:
1. Setting up a project in Visual Studio.
2. Navigating the Properties tab.
3. Understanding the boundaries and distinctions of a C# class.
4. Finding and Choosing Events Handlers (also known as the behavior or method of the code).
Key Terms: class, event handler, method, namespace, keyword, public, private, void
Alright, first practicum down!
And no, you couldn't put together a Windows Form application based on my scattered notes.
There's a lot more going on underneath the hood, but here's "proof" I finished my first project. In future essays, I'll go for clarity and actually being able to explain this stuff.
C# is still quite misty to me, but this method of studying (pouring more into meta-learning, writing notes over several days, working on a custom project with slight tutorial help and Googling) is much more intensive than what I was doing before (isolated tutorials) and, therefore, feels less illusive.
We'll keep peeling back the layers bit by bit, and eventually I can put together a one-pager that'll reach elegant brevity. That's the dream.
Until next time.
In Excelsis Deo. (And Merry Christmas!)
K.W. writes novels, short stories, the occasional ode, game scripts, and (with actual evidence!), this here blog.