Sign in with
Sign up | Sign in
Your question

Learing another language just by reading code

Last response: in Applications
Share
July 14, 2012 8:56:01 PM

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
a b L Programming
July 14, 2012 10:27:53 PM

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.
July 15, 2012 1:11:05 AM

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.
Related resources
July 15, 2012 7:41:31 AM

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.
a b L Programming
July 15, 2012 7:55:32 AM

Let's take a simple example of some code in an unfamiliar language:
  1. "SimpleEcho -- a simple TCP echo server in *********"
  2.  
  3. "Load the TCP package"
  4. PackageLoader fileInPackage: 'TCP'!
  5.  
  6. "Define a class for our server, it stores (so far) a server socket"
  7. Object subclass: #SimpleEchoServer
  8. instanceVariableNames: 'ss'
  9. classVariableNames: ''
  10. poolDictionaries: ''
  11. category: 'SimpleEcho'!
  12.  
  13. "Define a class method to create an instance given a port number"
  14. !SimpleEchoServer class methodsFor: 'instance creation'!
  15.  
  16. port: anInteger
  17. | ses |
  18. ses := super new.
  19. ses init: anInteger.
  20. ^ses
  21. !!
  22.  
  23. "Instance method for initialization from above class method"
  24. !SimpleEchoServer methodsFor: 'instance initialization'!
  25.  
  26. init: anInteger
  27. ss := (TCP.ServerSocket port: anInteger).
  28. ^self
  29. !!
  30.  
  31. "Instance method to handle running the main (infinite) loop"
  32. !SimpleEchoServer methodsFor: 'running'!
  33.  
  34. run
  35. | s |
  36. [
  37. ss waitForConnection.
  38. s := (ss accept).
  39. [self handleSocket: s] fork
  40. ] repeat
  41. !!
  42.  
  43. "Instance method to handle each connection"
  44. !SimpleEchoServer methodsFor: 'handling'!
  45.  
  46. handleSocket: s
  47. [
  48. | msg |
  49. msg := (s nextLine).
  50. msg displayOn: s.
  51. (String with: (Character value: 10)) displayOn: s.
  52. s flush
  53. ] repeat
  54. !!
  55.  
  56. "Create an echo server"
  57. Smalltalk at: #echoServer put: (SimpleEchoServer port: 8000)!
  58.  
  59. "Run it!"
  60. echoServer run!
Do you think you could understand the syntax and subtleties of this language just by studying the code?
July 17, 2012 12:56:13 PM

Ijack said:
Let's take a simple example of some code in an unfamiliar language:
  1. "SimpleEcho -- a simple TCP echo server in *********"
  2.  
  3. "Load the TCP package"
  4. PackageLoader fileInPackage: 'TCP'!
  5.  
  6. "Define a class for our server, it stores (so far) a server socket"
  7. Object subclass: #SimpleEchoServer
  8. instanceVariableNames: 'ss'
  9. classVariableNames: ''
  10. poolDictionaries: ''
  11. category: 'SimpleEcho'!
  12.  
  13. "Define a class method to create an instance given a port number"
  14. !SimpleEchoServer class methodsFor: 'instance creation'!
  15.  
  16. port: anInteger
  17. | ses |
  18. ses := super new.
  19. ses init: anInteger.
  20. ^ses
  21. !!
  22.  
  23. "Instance method for initialization from above class method"
  24. !SimpleEchoServer methodsFor: 'instance initialization'!
  25.  
  26. init: anInteger
  27. ss := (TCP.ServerSocket port: anInteger).
  28. ^self
  29. !!
  30.  
  31. "Instance method to handle running the main (infinite) loop"
  32. !SimpleEchoServer methodsFor: 'running'!
  33.  
  34. run
  35. | s |
  36. [
  37. ss waitForConnection.
  38. s := (ss accept).
  39. [self handleSocket: s] fork
  40. ] repeat
  41. !!
  42.  
  43. "Instance method to handle each connection"
  44. !SimpleEchoServer methodsFor: 'handling'!
  45.  
  46. handleSocket: s
  47. [
  48. | msg |
  49. msg := (s nextLine).
  50. msg displayOn: s.
  51. (String with: (Character value: 10)) displayOn: s.
  52. s flush
  53. ] repeat
  54. !!
  55.  
  56. "Create an echo server"
  57. Smalltalk at: #echoServer put: (SimpleEchoServer port: 8000)!
  58.  
  59. "Run it!"
  60. echoServer run!
Do you think you could understand the syntax and subtleties of this language just by studying the code?


Unfamiliar to who? ;) 
a b L Programming
July 17, 2012 2:56:57 PM

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.
July 17, 2012 4:12:22 PM

^LoL!

I think LISP would have been worse. ;) 
a b L Programming
July 17, 2012 5:00:17 PM

Lots of Irritating Silly Parentheses.
July 30, 2012 10:25:18 AM

Ijack said:
Let's take a simple example of some code in an unfamiliar language:
  1. "SimpleEcho -- a simple TCP echo server in *********"
  2.  
  3. "Load the TCP package"
  4. PackageLoader fileInPackage: 'TCP'!
  5.  
  6. "Define a class for our server, it stores (so far) a server socket"
  7. Object subclass: #SimpleEchoServer
  8. instanceVariableNames: 'ss'
  9. classVariableNames: ''
  10. poolDictionaries: ''
  11. category: 'SimpleEcho'!
  12.  
  13. "Define a class method to create an instance given a port number"
  14. !SimpleEchoServer class methodsFor: 'instance creation'!
  15.  
  16. port: anInteger
  17. | ses |
  18. ses := super new.
  19. ses init: anInteger.
  20. ^ses
  21. !!
  22. atleast i don't understand it :-p
  23. "Instance method for initialization from above class method"
  24. !SimpleEchoServer methodsFor: 'instance initialization'!
  25.  
  26. init: anInteger
  27. ss := (TCP.ServerSocket port: anInteger).
  28. ^self
  29. !!
  30.  
  31. "Instance method to handle running the main (infinite) loop"
  32. !SimpleEchoServer methodsFor: 'running'!
  33.  
  34. run
  35. | s |
  36. [
  37. ss waitForConnection.
  38. s := (ss accept).
  39. [self handleSocket: s] fork
  40. ] repeat
  41. !!
  42.  
  43. "Instance method to handle each connection"
  44. !SimpleEchoServer methodsFor: 'handling'!
  45.  
  46. handleSocket: s
  47. [
  48. | msg |
  49. msg := (s nextLine).
  50. msg displayOn: s.
  51. (String with: (Character value: 10)) displayOn: s.
  52. s flush
  53. ] repeat
  54. !!
  55.  
  56. "Create an echo server"
  57. Smalltalk at: #echoServer put: (SimpleEchoServer port: 8000)!
  58.  
  59. "Run it!"
  60. echoServer run!
Do you think you could understand the syntax and subtleties of this language just by studying the code?

!