Learing another language just by reading code

So basicly I am a young developer and I have written code with c++ c# pytyhon java and javascript Making many things.
But could you learn a whole language based on what you know already to understand a whole language just by reading code examples??

--Cavan
9 answers Last reply
More about learing language reading code
  1. You can learn most of the basic syntax, enough to write simple programs, but in order to fully take advantage of the language, and understand things you should do and not do, then you need some courses to supplement your code knowledge.
  2. Thanks for the reply it was very much a general question hanging on in my mind.
    Not my way to do it though as I am going to stick with books ;) .
    but I agree with the fact you need to read certain things about different languages.
  3. Think of it this way as an example. You know C++ and you start reading C# code. Can you learn about garbage collectors without referencign it from somewhere?
    Reading code is a great way to learn basics of a language, but you still need to find out the key differences, pros and cons of a language.
  4. Let's take a simple example of some code in an unfamiliar language:
    "SimpleEcho -- a simple TCP echo server in *********"
    
    "Load the TCP package"    
    PackageLoader fileInPackage: 'TCP'!
    
    "Define a class for our server, it stores (so far) a server socket"
    Object subclass: #SimpleEchoServer
      instanceVariableNames: 'ss'
      classVariableNames: ''
      poolDictionaries: ''
      category: 'SimpleEcho'!
    
    "Define a class method to create an instance given a port number"    
    !SimpleEchoServer class methodsFor: 'instance creation'!
    
    port: anInteger
      | ses |
      ses := super new.
      ses init: anInteger.
      ^ses
    !!
    
    "Instance method for initialization from above class method"
    !SimpleEchoServer methodsFor: 'instance initialization'!
    
    init: anInteger
      ss := (TCP.ServerSocket port: anInteger).
      ^self
    !!
    
    "Instance method to handle running the main (infinite) loop"
    !SimpleEchoServer methodsFor: 'running'!
    
    run
      | s |
      [
        ss waitForConnection.
        s := (ss accept).
        [self handleSocket: s] fork
      ] repeat
    !!
    
    "Instance method to handle each connection"
    !SimpleEchoServer methodsFor: 'handling'!
    
    handleSocket: s
      [
        | msg |
        msg := (s nextLine).
        msg displayOn: s.
        (String with: (Character value: 10)) displayOn: s.
        s flush
      ] repeat
    !!
    
    "Create an echo server"    
    Smalltalk at: #echoServer put: (SimpleEchoServer port: 8000)!
    
    "Run it!"
    echoServer run!
    Do you think you could understand the syntax and subtleties of this language just by studying the code?
  5. Ijack said:
    Let's take a simple example of some code in an unfamiliar language:
    "SimpleEcho -- a simple TCP echo server in *********"
    
    "Load the TCP package"    
    PackageLoader fileInPackage: 'TCP'!
    
    "Define a class for our server, it stores (so far) a server socket"
    Object subclass: #SimpleEchoServer
      instanceVariableNames: 'ss'
      classVariableNames: ''
      poolDictionaries: ''
      category: 'SimpleEcho'!
    
    "Define a class method to create an instance given a port number"    
    !SimpleEchoServer class methodsFor: 'instance creation'!
    
    port: anInteger
      | ses |
      ses := super new.
      ses init: anInteger.
      ^ses
    !!
    
    "Instance method for initialization from above class method"
    !SimpleEchoServer methodsFor: 'instance initialization'!
    
    init: anInteger
      ss := (TCP.ServerSocket port: anInteger).
      ^self
    !!
    
    "Instance method to handle running the main (infinite) loop"
    !SimpleEchoServer methodsFor: 'running'!
    
    run
      | s |
      [
        ss waitForConnection.
        s := (ss accept).
        [self handleSocket: s] fork
      ] repeat
    !!
    
    "Instance method to handle each connection"
    !SimpleEchoServer methodsFor: 'handling'!
    
    handleSocket: s
      [
        | msg |
        msg := (s nextLine).
        msg displayOn: s.
        (String with: (Character value: 10)) displayOn: s.
        s flush
      ] repeat
    !!
    
    "Create an echo server"    
    Smalltalk at: #echoServer put: (SimpleEchoServer port: 8000)!
    
    "Run it!"
    echoServer run!
    Do you think you could understand the syntax and subtleties of this language just by studying the code?


    Unfamiliar to who? ;)
  6. Unfamiliar to those who are not familiar with it. I would guess that covers at least 95% of the posters here.

    At least I didn't pick APL or RPG.
  7. ^LoL!

    I think LISP would have been worse. ;)
  8. Lots of Irritating Silly Parentheses.
  9. Ijack said:
    Let's take a simple example of some code in an unfamiliar language:
    "SimpleEcho -- a simple TCP echo server in *********"
    
    "Load the TCP package"    
    PackageLoader fileInPackage: 'TCP'!
    
    "Define a class for our server, it stores (so far) a server socket"
    Object subclass: #SimpleEchoServer
      instanceVariableNames: 'ss'
      classVariableNames: ''
      poolDictionaries: ''
      category: 'SimpleEcho'!
    
    "Define a class method to create an instance given a port number"    
    !SimpleEchoServer class methodsFor: 'instance creation'!
    
    port: anInteger
      | ses |
      ses := super new.
      ses init: anInteger.
      ^ses
    !!
    atleast i don't understand it :-p
    "Instance method for initialization from above class method"
    !SimpleEchoServer methodsFor: 'instance initialization'!
    
    init: anInteger
      ss := (TCP.ServerSocket port: anInteger).
      ^self
    !!
    
    "Instance method to handle running the main (infinite) loop"
    !SimpleEchoServer methodsFor: 'running'!
    
    run
      | s |
      [
        ss waitForConnection.
        s := (ss accept).
        [self handleSocket: s] fork
      ] repeat
    !!
    
    "Instance method to handle each connection"
    !SimpleEchoServer methodsFor: 'handling'!
    
    handleSocket: s
      [
        | msg |
        msg := (s nextLine).
        msg displayOn: s.
        (String with: (Character value: 10)) displayOn: s.
        s flush
      ] repeat
    !!
    
    "Create an echo server"    
    Smalltalk at: #echoServer put: (SimpleEchoServer port: 8000)!
    
    "Run it!"
    echoServer run!
    Do you think you could understand the syntax and subtleties of this language just by studying the code?
Ask a new question

Read More

Programming C# Javascript Java Apps