I am familiar with Python language (3 years) and I’m learning Scala. When learning a language we memorize it by comparing it with other languages we know. It is a fun way to explore the language. Here is a list of syntax differences I noticed in the above 3 languages. Do you agree with them?
# | Python | Java | Scala |
1 | has a return statement | has a return statement | return statement is optional |
2 | : is used to indicate the start of a new block of code such as a loop, function or conditional statement. | { is used in contexts where some group of things will be treated as a unit, whether it’s a block statement (many statements treated as a single one), a class (many methods and fields treated as a single object), a method (many statements treated as a single unified piece of code), an initializer (many things that need to be done at once), etc. | { or ( The rules are somewhat diffuse. Basically, you’ll have to get the hang of it. Perhaps it is best to concentrate on where curly braces and parentheses can be used interchangeably: when passing parameters to method calls. You may replace curly braces with parentheses if, and only if, the method expects a single parameter. reference |
3 | : as a mapping inside a dictionary | => | => |
4 | No | ; is used to terminate a statement | No |
5 | variable defined without type new_list = [] | Mention the data type when defining a new variable int index = -1; | variable defined without type and val key word val index =0 |
6 | join() | append() | mkString() |
7 | words = s.split(‘ ‘) | String[] str = s.split(” “); | var str = s.split(” “) |
8 | indentation is mandatory | indentation is not mandatory. code looks better | indentation is not mandatory. code looks better |