May 18, 2015

Week of 05/10/15 - C++ Part 5: New Computers, New Problems

    This Tuesday, I was not in class because of testing, so I apologize if this post is short.

    On Thrusday, I discovered that our computer lab got some new computers while I was testing. I was not aware we would be getting new computers, so I lost everything. Luckily none of it was important. The class was spent getting used to OSX 10.10 Yosemite, along with installing Codeblocks, and installing Xcode so that I can use GCC, the GNU Compiler Collection, in the command line to compile C++ I write in text files. However, after many compiler problems and issues that I was trying to fix, I decided to move from Code::Blocks to CodingGround, the online site I used for Python.

May 14, 2015

Week of 05/03/15 - C++ Part 4: Functions

    From previous C++ experience, I know that functions are series of statements. From experience, the program starts by running the main function. However, if there are multiple functions, the main function is still the only one that is run. This is unless you use a function call in the main function. A function call interrupts the main function by leaving a "bookmark" in the main function and then calls, or executes, the specified function. When that function terminates, the program goes back to the bookmark and continues running the main function. Also, function calls are made using the function name along with a list of parameters enclosed by parenthesis. I wanted to see if you could call functions within functions other than main(), but it doesn't look like you can, according to stackoverflow. Functions also can't be defined inside of other functions. For example, you can't define your function when it's in main(). You have to define it outside of main().

    The main function has an integer type, so in the end it return a number, usually 0. Other functions can have other types, though. We have the void type, where the function returns nothing. There's integer, there's also probably boolean, string, array, and possibly more.

    The website mentions the question "Can my function return multiple values using a return statement?". It says no, but it also says that there are workarounds for that. Probably arrays and parsing them after they are returned.

April 30, 2015

Week of 04/26/15 - C++ Part 3: Experimentation

    The std::cout << object from iostream is used to output text to the console, and the output operator can be used to print multiple things on the same line. From what I see, to make your code look clean, you can also just have multiple lines of std::cout << without having a << endl; statement at the end, though I don't see why someone would need an output that long, or why they wouldn't use a string variable instead. However, when printing from the console, the spacing in the string is important, like when you're trying to print "Your name is X" on the console. You don't want to make it say "Your name isX", so you need to add a space at the end of the string so that the variable isn't conjoined with the string.
    std::cin >> is similar to std::cout, except it works in the opposite direction, and it requires input. It takes input from the console and then puts it in a variable.
    std is a special container, or a namespace, for everything inside the standard library. Putting std:: before cin, cout, endl, and probably other functions makes the compiler check for the function in the standard library's namespace. However, for some people, this becomes a chore. This is why we have the using directive. With a using directive, you can write using namespace std and then it would look for all the functions in your code in the standard library. However, doing this could cause a naming collision between the standard library's function and a function you wrote yourself. You can also do this for individual functions like using std::cout, which maps only cout to the standard library.
    I also did an experiment today. I wanted to see if an executable compiled with std:: would differ from an executable compiled with a using std::cout. I compiled them both, and ran them through an md5 hash checker, which takes the data of the file and based on the data, and returns a checksum. This checksum is constant if the data does not change, and the checksum changes greatly if the data is changed. Also, two files with the same data return the same checksum. And when I ran the two files that were compiled with different code through the md5 hash checker, they had the same checksum. Which means that both of the files were the same, even with different code. I think this is because doing the namespace thing just tells the compiler where to look for the functions like cout, cin, and endl.

April 24, 2015

Week of 04/19/15 - C++ Part 2: Compiling, Building, and Running

    I began Monday by installing the GCC Compiler for C++. Code::Blocks started up and I selected GCC to be the compiler. I followed the tutorial for a "Hello World" program, and apparently Code::Blocks starts off the command-line based program with a pre-made "Hello World" program. The program was "built" and run, and it opened a command window, said "Hello world!", and returned 0 at the end. However, I wanted to get a feel for the language, so I re-typed it entirely by hand.

    The tutorial went through build configurations, which are compilation settings, and the 2 default ones are debug and release. The debug configuration adds some stuff on compilation that lets you debug the program more easily, while the release configuration is more optimized and lacks any debugging add-ons. The release configuration is used to release code for download and running on computers, while the debug configuration is for development.

    Next, I learned about C++ structure. A statement conveys to the compiler that a task needs to be done. Statements are terminated by semicolons, and come in several different type. There are: declaration statements, which declare variables; assignment variables, which assign values to variables; and output statements, which outputs the value of a variable to the screen. Then there are expressions, which are operations, like addition or a function.

    A function is a collection of statements that run sequentially. Every program in C++ requires a function, called the main() function. Upon execution of the program, the first statement in the main() function is run.

    Libraries are pre-compiled code for reuse in many projects. C++ comes with the C++ Standard Library, for additional functionality. At the beginning of the program, you need to add any headers, like &ltiostream&gt from the standard library, and any headers from any other libraries you need.
    For my own learning purposes, &lt&lt is an output operator, and std::cout &lt&lt prints out whatever the output operator sends its way. At the end of the main function, there needs to be an indicator to the operating system that the code ran successfully or not; a zero means the code ran successfully. Anything non-zero is usually some sort of error.

     Comments can be made in 2 ways, the double slash (//comment) or the multiline (/*comment*/). Unlike html tags, multi-line comments do not nest, meaning that on the first */, the comment ends, and you shouldn't be nesting them anyways. Comments on functions, libraries, or programs, should be what they do. Comments on the code inside of functions and programs should be how the code is doing what it's doing. At the statement level, there needs to be even more detail, telling why you do something, and about any decisions you made on how the program functions. You can also comment out code, so that the code doesn't compile, in the event the code doesn't work and needs to be fixed, you're replacing code.

April 16, 2015

Week of 04/12/15 - C++ Part 1: Learning to Develop

    With my introduction to C++, LearnCpp has shown me the process of development, which is: defining the problem, designing a solution, writing a program that implements the solution, compiling the program, linking object files, testing, and debugging.

    The first part, defining the problem, is simply figuring out what you want your program to do. You can't write code for something when you don't know what it does.

    Designing a solution is determining how you solve the problem that you defined. Apparently, this is often neglected, because there are many ways to solve the problem. Good solutions are straightforward, well documented, modularized, and can be easily extended, for future-proofing.

    Next comes writing the program. This requires knowledge of a programming language and an editor. An optimal editor is one that has line numbers, syntax highlighting, coloring, and an unambiguous font.

    Compiling comes after writing, and it requires a compiler, which checks for syntax and turns source code into an object file. I am using a Mac, which runs a unix operating system. A really well known compiler for unix is called gcc and is called from the command line. However, it is not installed by default on this Mac, so I'm going to either have to use an online service, or somehow install gcc on my Mac.

    Linking combines object files and files from the runtime support library to create an executable file. You can also compile and link files with one command.

    At the end of the intro to development page, it recommends use of an IDE for development because it bundles the software used from writing code to debugging.

    The next page makes recommendations for IDEs. It gave one suggestion that I am familiar with, called Code::Blocks. One of my friends showed me this before, so I guess I'll use it. However, it says it supports compilers, so I'm still going to have to install a working compiler, probably gcc because I have just found and downloaded an installer for it. The site also recommends using Xcode or eclipse, but eclipse doesn't look too good out of the box, and neither does Xcode. Code::Blocks and eclipse both have plugin support, so I will choose to use on of those two.

April 10, 2015

Week of 04/05/15 - Python Part 26: Finished Up

    This project has taken up a lot of my time. So, to just finish it and move on, what I'm going to do is remove the references to the row and the column, because I can't get them to work outside of the turn() function. So what I'm going to do is have it check every row, column, and diagonal every turn. On Monday, I had tried moving most of the contents of the turn() function to outside it, but I didn't know what it did, so I just reverted everything back. Now, I've made the code look like:

    def column_checker(column, board):
        if board[0][0] == board[1][0] == board[2][0] \
        or board[0][1] == board[1][1] == board[2][1] \
        or board[0][2] == board[1][2] == board[2][2]:
            return 1
        else:
            return 0


    I was testing it with my friend Felipe, who sits next to me in class, and it works how it should. I'm probably going to test it out with a few other people later. But now that I have that project out of the way, I kind of want to move away from Python. I've been doing this for the past semester and a third. I want something new. I want to learn something more lower level. I want to learn C or C++.

    On Friday, the morning was spent figuring out which one to learn; I decided to learn C++ because it can make programs with a GUI, and is a pretty common language. I'm going to learn using the website http://www.learncpp.com because I saw it recommended on several websites, including stackoverflow.

    The tutorial starts out with explanation of instruction sets in binary, assembly, and then higher level languages. For higher level languages it described compilers and interpreters. Then it goes into a history of C itself. I didn't know that because C was so portable, able to compile on many different types of computers, that Ken Thompson and Dennis Ritchie rewrote Unix from assembly to C. A formal standard for C was created by some committee in the 80's, and C++ was developed as an extension to C in 1979, but C++ was only ratified in 1998; a new version, C++03, was ratified in 2003, and C++11 was ratified in 2011. The site says it teaches C++03, and any additions by C++11 will be in the appendix. It also says that C++ is object oriented.

April 6, 2015

Week of 03/29/15 - Python Part 25: Implementation, Among Other Things

    I started out the week by beginning the integration of the new checking function into my code. First, what I needed to do was remove the original checking function, which I did swiftly. Then, I had to set the flag number to be equal to the output of the flag checker function, and then I had to write an if statement for when it equals 1 or if it was more than one. Then, I had to write the congratulations function, for both the string and the ASCII art from the text file. Then, I began to play the game to test if it worked. It worked, in a sense. When I would get multiple rows, the game would print out the congratulations ASCII art, and with singles, it would work correctly, except the bottom-left to top-right diagonal still isn't recognized. When I put in some debugging code, when I add together the row and the column, it returns 0, even though it should return 2. This problem has been going on for a pretty long time. I will fix it next week.