Computer Science Canada

How to begin understanding new languages?

Author:  LimeWan [ Wed Aug 07, 2013 1:31 am ]
Post subject:  How to begin understanding new languages?

I have taken computer science during the past two years of high school, and am going into grade 12 this fall.

For grades 10 and 11, out school using Turing, and will begin teaching Java in grade 12.

The issue is, after really getting into programming this year, I want to invest my spare time learning a more well accepted language (C++ or Java), but seem to be having trouble understanding how 'real' languages work.

With Turing, all you need to know is how to enter text into the IDE, and that's it. With all of these other languages, you now worry about all of these external files and components that make the program function.

My question is, in general, how can I learn how these other languages are structured. I do not care for the so called 'tutorials', as I have watched and read a great deal of them, but all they seem to do is introduce you to the syntax. I want to know how these more 'advanced' languages work. What are all of the different 'stuff' that can be used in the language?

My question may seem a little confusing, but what I really want to get out of this question is learning the different components of languages, and how to use them, when to use them, etc.

I am sure that we will learn this stuff at the beginning of the school year, but I would really like to expand my knowledge beyond what the school teaches, and on my own time as well.

Thank you!

Author:  Insectoid [ Wed Aug 07, 2013 5:12 am ]
Post subject:  RE:How to begin understanding new languages?

Quote:
With Turing, all you need to know is how to enter text into the IDE, and that's it.


This isn't really true at all. You still need to understand the various commands and functions and the logic to apply them. This is the same for every language.

Quote:
With all of these other languages, you now worry about all of these external files and components that make the program function.


These are mostly just libraries full of useful functions you can use.

Quote:
how can I learn how these other languages are structured.


Read some tutorials. Some languages are very similar to Turing. Some are completely different. Most languages subscribe to a specific 'paradigm' such as 'object-oriented', 'functional', or 'imperative'. Turing is imperative. To understand Java, you must first understand object-oriented programming. To understand Haskell, you must understand functional programming. Some tutorials assume you already understand the paradigm and therefore only teach the syntax. Some will teach you a paradigm without teaching a language at all.

Quote:
I do not care for the so called 'tutorials', as I have watched and read a great deal of them, but all they seem to do is introduce you to the syntax.


You've been reading the wrong tutorials then.


Quote:
I want to know how these more 'advanced' languages work. What are all of the different 'stuff' that can be used in the language?


Most languages outside of Turing are massive. They have dozens of libraries with hundreds or thousands of functions. It takes years to learn all of it. It's more important to understand the core of the language so that you don't need all of the hundreds of functions, but can look them up and use them to save time.

Quote:
but what I really want to get out of this question is learning the different components of languages, and how to use them, when to use them, etc.


Again, this is a hugely broad question with no easy answer. It takes years to understand a language to this degree. I'm certain you don't even fully understand the power Turing has, even as you grow tired of its limitations. You're looking for an easy answer to a question that has none.

Author:  rdrake [ Wed Aug 07, 2013 8:59 am ]
Post subject:  Re: How to begin understanding new languages?

http://mitpress.mit.edu/sicp/!

One of the first real languages I used was Ruby. They even have a wonderful interactive tutorial you can do online. I think this will be a lot more helpful than a standard tutorial.

Author:  mirhagk [ Wed Aug 07, 2013 8:22 pm ]
Post subject:  RE:How to begin understanding new languages?

It takes a very short amount of time to learn all the syntax of C. It takes many lifetimes to learn all the different ways that syntax can be used to create programs.

My favourite language is BrainF**k, it can be taught to anyone who has elementary programming experience (has gotten as far as arrays), yet it would take years to know enough to create a useful program

Author:  btiffin [ Thu Aug 08, 2013 1:41 am ]
Post subject:  Re: How to begin understanding new languages?

GNU/Linux.

Designed by and for developers, a long time ago. Now free and vast. Vast.

Vast.

Allowing unfettered exploration of any and all computation models you can think of.

Want to learn some mainframe? Hercules 390 emulator and an old 1972 MVS system for the Job Control Language (and JCL hasn't really changed much).

Science and either big data filter or graphing programming?

GUI, TUI, CLI, Networked, Audible, Cloud based robot thingies

Oh, and on and on. C, Forth, COBOL, Prolog, Assembler. small s.c.r.i.p.t (I just wrote that one, and posted an esolang page at http://esolangs.org/wiki/Small_s.c.r.i.p.t. so now I'm bragging. Language tools are a lot of fun. Toys are more fun. Toyols are in between the fun and the more fun.)

Anyway. Start with a GNU/Linux distribution. If you stick to the top 10 you won't go wrong, so don't fret too much about which distro to try first. After that, software development tools and the documentation on how to wield them are just waiting to be discovered. Docs not enough? Open up the source files and learn from those that came before. Ok, to be honest, to be truly happy in GNU/Linux land, learn some C. POSIX and a fair chunk of the internet infrastructure is in C (most?). Knowing how to cypher through C code, means everything else is easier to get to.

Cheers

Author:  ArabiaAvonlea [ Tue Oct 22, 2013 4:15 am ]
Post subject:  Re: How to begin understanding new languages?

Understanding Language launches a set of new, open source mathematics materials designed for teachers of ELLs.

Author:  yazdmich [ Tue Oct 22, 2013 12:27 pm ]
Post subject:  Re: How to begin understanding new languages?

Python, like Turing, is an AMAZING language to learn for beginners. again, like turing, python is imperative, but the OOP syntax is very simple as well ("everything is an object" is a good analogy, trust me). I've even translated a turing program to python, converted it to a class, and then modified it further. Python also has far more clear syntax (and no variable declaration, you can just assign a value to a new variable and BAM! variable made, also no type declaration). I recommend reading up about it, and Codecademy has a very good python course as well.

Author:  Raknarg [ Tue Oct 22, 2013 12:39 pm ]
Post subject:  RE:How to begin understanding new languages?

Yuck. I can't wait till I'm finished with python.

Author:  yazdmich [ Tue Oct 22, 2013 1:44 pm ]
Post subject:  Re: RE:How to begin understanding new languages?

Raknarg @ Tue Oct 22, 2013 12:39 pm wrote:
Yuck. I can't wait till I'm finished with python.

Huh? its at least better than Turing in terms of speed and portability. If not a good practical language, its a good teaching language.
Turing:
var y : array 0 .. 9 of int
for x : 0 .. 9
    y(x) := x**2
end for


Python:
# list comprehension
y = [x**2 for x in range(10)]
# or this, in regular syntax
y = []
for x in range(10):
    y.append(x**2)

Author:  Tony [ Tue Oct 22, 2013 2:27 pm ]
Post subject:  RE:How to begin understanding new languages?

http://xkcd.com/353/

Posted Image, might have been reduced in size. Click Image to view fullscreen.


Python is a good practical language, especially in math/science domains, via the extensive library support.

Author:  yazdmich [ Tue Oct 22, 2013 2:42 pm ]
Post subject:  Re: RE:How to begin understanding new languages?

yazdmich @ Tue Oct 22, 2013 1:44 pm wrote:
Raknarg @ Tue Oct 22, 2013 12:39 pm wrote:
Yuck. I can't wait till I'm finished with python.

Huh? its at least better than Turing in terms of speed and portability. If not a good practical language, its a good teaching language.
Turing:
var y : array 0 .. 9 of int
for x : 0 .. 9
    y(x) := x**2
end for


Python:
# list comprehension
y = [x**2 for x in range(10)]
# or this, in regular syntax
y = []
for x in range(10):
    y.append(x**2)

correction: i meant that even if you don't see it as a good practical language, its still a great teaching language.
An example Python module:
Python:
#-------------------------------------------------------------------------------
# Name:           Crypto
# Purpose:       Vernam cipher with hex output module
#
# Author:       Michael M. Yazdani
#
# Created:       03/05/2013
# Copyright:   (c) Michael M. Yazdani 2013
# Licence:       N/A
#-------------------------------------------------------------------------------
#!/usr/bin/env python
import random
random.seed()

def csr(x):
    if x % 2 == 1:
        return (x >> 1) + 64
    elif x % 2 == 0:
        return x >> 1

def csl(x):
    if x < 64:
        return x << 1
    else:
        return ((x - 64) << 1) + 1

class Crypto:
    def __init__(self, name, msg):
        self.decoded = ""
        self.encoded = ""
        self.alphas = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz,.?\"'()[]{}1234567890<>;:!@#$%^&*`~/\\-=_+ "
        self.name = name
        self.msg = msg
        if not(self.name == 'gen'):
            stream = open("keys/"+self.name)
            if (stream):
                self.key = stream.read()
                stream.close()
            else:
                print("Error, key not found, make sure its in the key folder and you spelled it right")
                stream.close()

    def update(self, msg):
        self.msg = msg

    def get_key(self):
        stream = open("keys/"+self.name)
        if (stream):
            self.key = stream.read()
            stream.close()
            return self.key
        else:
            print("Error, key not found, make sure its in the key folder and you spelled it right")
            stream.close()

    def In(self):
        self.encode = self.msg
        self.encoded = ""
        for x in range(0, len(self.encode)):
            self.encoded += hex(csl(csr(ord(self.key[x % len(self.key)]))^ord(self.encode[x])))+" "
        return self.encoded

    def Out(self):
        self.encoded = self.msg.split(' ')
        self.decoded = ""
        del self.encoded[len(self.encoded)-1]
        for x in range(0, len(self.encoded)):
            self.decoded += chr(csr(int(self.encoded[x], base=16))^csr(ord(self.key[x % len(self.key)])))
        return self.decoded

    def gen_key(self, name):
        self.key = ""
        used = [False]
        check = []
        for i in range(len(self.alphas)):
                used.append(False)
        for i in range(len(self.alphas)):
            var = True
            while var:
                num = random.randint(0, len(self.alphas)-1)
                if (used[num] == False):
                    check.append(num)
                    var = False
            used[num] = True
            self.key += self.alphas[num]
        check = sorted(check)
        print(check)
        print("New key: " + self.key)
        stream = open("keys/"+name, mode='w')
        stream.write(self.key)
        stream.close()

class CryptIO:

    def __init__(self, fin, fout, key):
        self.file = open(fin)
        self.file2 = open(fout, 'w')
        Crypto.__init__(self, key, '')

    def close(self):
        self.file.close()
        self.file2.close()

    def In(self):
        for line in self.file:
            Crypto.update(self, line)
            fin = Crypto.In(self)
            print(line)
            print(fin)
            self.file2.write(fin+'\n')
        self.close()

    def Out(self):
        for line in self.file:
            Crypto.update(self, line)
            fout = Crypto.Out(self)
            print(line)
            print(fout)
            self.file2.write(fout)
        self.close()

Author:  BigBear [ Tue Oct 22, 2013 3:10 pm ]
Post subject:  Re: RE:How to begin understanding new languages?

Tony @ Tue Oct 22, 2013 2:27 pm wrote:
http://xkcd.com/353/

[img]http://imgs.xkcd.com/comics/python.png[/img


Python is a good practical language, especially in math/science domains, via the extensive library support.


Does that mean you prefer Python over Ruby? Or just recommending Python for beginners?

Author:  Raknarg [ Tue Oct 22, 2013 4:13 pm ]
Post subject:  RE:How to begin understanding new languages?

Oh, I know python is great, and there's been times where I was happy I was using it, but I prefer not to use it.

Personally I'm having a lot of fun with Processing.

Author:  Tony [ Tue Oct 22, 2013 8:47 pm ]
Post subject:  Re: RE:How to begin understanding new languages?

BigBear @ Tue Oct 22, 2013 3:10 pm wrote:
Does that mean you prefer Python over Ruby?

It means it depends on the application. If I want to perform simulations for a writeup such as http://what-if.xkcd.com/25/ and I need something that will give me "scientific-grade astronomical computations" ( http://rhodesmill.org/pyephem/ ) then Python is where it's at.

If I want a web application, then Ruby has much better frameworks.

Author:  Nathan4102 [ Tue Oct 22, 2013 8:59 pm ]
Post subject:  Re: RE:How to begin understanding new languages?

Tony @ Tue Oct 22, 2013 9:47 pm wrote:
BigBear @ Tue Oct 22, 2013 3:10 pm wrote:
Does that mean you prefer Python over Ruby?

It means it depends on the application. If I want to perform simulations for a writeup such as http://what-if.xkcd.com/25/ and I need something that will give me "scientific-grade astronomical computations" ( http://rhodesmill.org/pyephem/ ) then Python is where it's at.

If I want a web application, then Ruby has much better frameworks.


That's funny, I remember Python getting bizarre answers for the simplest math calculations. 4/2 = 1.9999999999999999999999999, or something like that...

Author:  yazdmich [ Tue Oct 22, 2013 9:07 pm ]
Post subject:  Re: RE:How to begin understanding new languages?

Nathan4102 @ Tue Oct 22, 2013 8:59 pm wrote:
Tony @ Tue Oct 22, 2013 9:47 pm wrote:
BigBear @ Tue Oct 22, 2013 3:10 pm wrote:
Does that mean you prefer Python over Ruby?

It means it depends on the application. If I want to perform simulations for a writeup such as http://what-if.xkcd.com/25/ and I need something that will give me "scientific-grade astronomical computations" ( http://rhodesmill.org/pyephem/ ) then Python is where it's at.

If I want a web application, then Ruby has much better frameworks.


That's funny, I remember Python getting bizarre answers for the simplest math calculations. 4/2 = 1.9999999999999999999999999, or something like that...

I just checked and Python 3.3 gives 2.0 for 4/2

Author:  Nathan4102 [ Tue Oct 22, 2013 9:09 pm ]
Post subject:  RE:How to begin understanding new languages?

It was a few months ago, so I don't remember the exact example, I just know it gave me weird numbers like that when I tried to divide. Maybe its been fixed

Author:  Tony [ Tue Oct 22, 2013 10:08 pm ]
Post subject:  RE:How to begin understanding new languages?

1. For most applications, that is close enough. (You might also be interested to know that another way to express the value 1 is 0.999...(repeating))
https://en.wikipedia.org/wiki/0.999...
Quote:

The equality 0.999... = 1 has long been accepted by mathematicians and is part of general mathematical education.

1.1 Yes, it really is close enough. https://en.wikipedia.org/wiki/Pi
Quote:

According to Jorg Arndt and Christoph Haenel, thirty-nine digits [of pi] are sufficient to perform most cosmological calculations, because that is the accuracy necessary to calculate the volume of the known universe with a precision of one atom.


2. The "weirdness" of floating point limitations comes out of your CPU anyway, and you'd be hitting the same limitations in any other language (provided that operations are performed using the fast native types).


: