The web app provides side-by-side examples of syntax differences between programming languages. You can use it as a cheatsheet or as a learning material to learn one of them through another. Creating these examples I tried to use the most used and the cleanest solutions.
All examples are executable. You can copy and launch them without changes. It helps to understand what the code is doing easily.
View web app here.
Created with:
All languages:
- It's possible to achieve anything with any language (especially with a library). However when a solution is really long and difficult to read it's better to not provide it
- Every task can be solved in different ways but it's preferable to provide not more than one the most used example
Java and Kotlin:
- 2 spaces is used to make the code more concise
Add more languages:
- Ruby - Elixir
- Ruby - Crystal
- Java - C#
- JavaScript - TypeScript
Install ruby:
$ ruby --version
Install dependencies:
$ bundle
Run the app in localhost (http://localhost:4567):
$ bundle exec middleman
To generate outputs below the examples:
- Install all interpreters/compilers needed
$ rake
To add a new language:
- Add the language to
langs
variable toconfig.rb
- Add a rake task to
Rakefile
to run all the examples to produce output files that are included to the final html - Add examples
To add an example:
- Modify
data/code.yml
- Add files to
code/
folder
Where can I provide a version?
- Python 2 vs Python 3
- Java 7 vs Java 8
- ES5 vs ES6
- New features that are not standard de-facto yet
Interpolation in Python is:
first = "Don't worry,"
second = 'be happy'
print('%s %s' % (first, second))
Since 3.6 you can use:
first = "Don't worry,"
second = 'be happy'
print(f'{first} {second}')
To achieve it:
- Change
data/code.yml
python:
.: string_interpolation.py
'3.6': string_interpolation.py
- Add the first example to
code/python/
- Add the second example to
code/python/3.6
git checkout source
bundle exec middleman build
bundle exec middleman deploy
Feel free to add or modify any examples.
- Fork it ( https://github.com/evmorov/lang-compare/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request