• Check out all the best Amazon Prime Day deals 2021 here!

Learing another language just by reading code

cavan21

Distinguished
Aug 2, 2011
4
0
18,510
0
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
 

PhilFrisbie

Distinguished
Apr 22, 2006
666
0
19,310
53
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.
 

cavan21

Distinguished
Aug 2, 2011
4
0
18,510
0
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.
 

theDanijel

Distinguished
May 4, 2011
74
0
18,590
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.
 

Ijack

Distinguished
Let's take a simple example of some code in an unfamiliar language:
Code:
"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?
 

Hawkeye22

Distinguished
Moderator


Unfamiliar to who? ;)
 

magnus71

Honorable
Jul 1, 2012
16
0
10,560
0

 
Thread starter Similar threads Forum Replies Date
A Apps General Discussion 1
L Apps General Discussion 1
T Apps General Discussion 8
T Apps General Discussion 5
A Apps General Discussion 1
A Apps General Discussion 1
L Apps General Discussion 5
G Apps General Discussion 5
T Apps General Discussion 3
D Apps General Discussion 1
P Apps General Discussion 1
Z Apps General Discussion 6
Boris_yo Apps General Discussion 2
N Apps General Discussion 1
S Apps General Discussion 1
S Apps General Discussion 3
S Apps General Discussion 1
S Apps General Discussion 2
J Apps General Discussion 5
UnforgivenGamer Apps General Discussion 3

ASK THE COMMUNITY