{"action":"created","comment":{"url":"https://api.github.com/repos/scala/scala.github.com/pulls/comments/99270393","pull_request_review_id":19942323,"id":99270393,"diff_hunk":"@@ -0,0 +1,207 @@\n+---\n+layout: tutorial\n+title: Basics\n+\n+disqus: true\n+\n+tutorial: scala-tour\n+num: 2\n+next-page: unified-types\n+previous-page: tour-of-scala\n+---\n+\n+In this page, we will cover basics of Scala.\n+\n+## Variables\n+\n+You can define variables with `var` keyword.\n+\n+```\n+var x = 1 + 1\n+x += 1\n+```\n+\n+Often, you want your variables to be immutable. You can use `val` keyword in that case.\n+\n+```\n+val x = 1 + 1\n+x += 1 // This does not compile because you declared the variable with \"val\" keyword\n+```\n+\n+Type of variables can be inferred, but you can also explicitly state type like below.\n+\n+```\n+val x: Int = 1 + 1\n+```\n+\n+## Functions\n+\n+You can define functions like below.\n+\n+```\n+(name: String) => println(\"Hello, \" + name + \"!\")\n+```\n+\n+You can also assign functions to variables.\n+\n+```\n+val greet = (name: String) => println(\"Hello, \" + name + \"!\")\n+greet(\"Scala\") // Hello, Scala!\n+```\n+\n+We will cover functions in depth [later](anonymous-function-syntax.md).\n+\n+## Classes\n+\n+You can define classes with `class` keyword.\n+\n+```\n+class Point(var x: Int, var y: Int) {\n+  def move(dx: Int, dy: Int): Unit = {\n+    x = x + dx\n+    y = y + dy\n+  }\n+\n+  override def toString: String = \"(\" + x + \", \" + y + \")\"\n+}\n+```\n+\n+You can instantiate classes with `new` keyword.\n+\n+```\n+val point = new Point(1, 2)\n+println(point) // (1, 2)\n+```\n+\n+We will cover classes in depth [later](classes.md).\n+\n+## Case Classes\n+\n+By default, classes are compared by reference. If you want to compare them by values, you need to override `equals` and `hashCode` methods.\n+\n+```\n+class Point(val x: Int, val y: Int) {\n+  override def equals(o: Any) = o match {\n+    case that: Point => x == that.x && y == that.y\n+    case _ => false\n+  }\n+  override def hashCode = (x.hashCode << 16) + y.hashCode\n+}\n+```\n+\n+While it works, it's tedious to define those methods for all classes you want to compare by value.\n+\n+Thankfully, Scala has another type of class called `case class` that's compared by value by default.\n+\n+```\n+case class Point(x: Int, y: Int)\n+```\n+\n+You can instantiate case classes without `new` keyword.\n+\n+```\n+val point = Point(1, 2) // no \"new\" here\n+val anotherPoint = Point(1, 2)\n+val yetAnotherPoint = Point(2, 2)\n+println(point == anotherPoint) // true\n+println(point == yetAnotherPoint) // false\n+```\n+\n+Case classes are immutable by default, but it also provides `copy` method so that you can easily create another instance of the class while reusing the values from exiting instances.\n+\n+Using `copy` method, you can also write the above code like below.\n+\n+```\n+val point = Point(1, 2)\n+val anotherPoint = point.copy()\n+val yetAnotherPoint = point.copy(x = 2)\n+println(point == anotherPoint) // true\n+println(point == yetAnotherPoint) // false\n+```\n+\n+Because of case classes, you almost never see classes overriding `equals` and `hashCode` methods in Scala.\n+\n+There are many other features you get out-of-the-box by using case classes. We will cover them in depth [later](case-classes.md).\n+\n+## Singleton Objects\n+\n+You can define singleton objects with `object` keyword.","path":"tutorials/tour/basics.md","position":128,"original_position":128,"commit_id":"054fb9cc60707cf067fdb20e93c7f5828bc10964","original_commit_id":"054fb9cc60707cf067fdb20e93c7f5828bc10964","user":{"login":"tpolecat","id":1200131,"avatar_url":"https://avatars.githubusercontent.com/u/1200131?v=3","gravatar_id":"","url":"https://api.github.com/users/tpolecat","html_url":"https://github.com/tpolecat","followers_url":"https://api.github.com/users/tpolecat/followers","following_url":"https://api.github.com/users/tpolecat/following{/other_user}","gists_url":"https://api.github.com/users/tpolecat/gists{/gist_id}","starred_url":"https://api.github.com/users/tpolecat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tpolecat/subscriptions","organizations_url":"https://api.github.com/users/tpolecat/orgs","repos_url":"https://api.github.com/users/tpolecat/repos","events_url":"https://api.github.com/users/tpolecat/events{/privacy}","received_events_url":"https://api.github.com/users/tpolecat/received_events","type":"User","site_admin":false},"body":"An `object` is a module. A namespace. Like a package, but unlike a package it's a value. When you say \"singleton\", as a Java programmer I think \"singleton of what?\" ... is `object Foo` an instance of `class Foo`? I realize \"singleton\" is the common usage but to me it's misleading.","created_at":"2017-02-03T03:14:31Z","updated_at":"2017-02-03T03:14:31Z","html_url":"https://github.com/scala/scala.github.com/pull/671#discussion_r99270393","pull_request_url":"https://api.github.com/repos/scala/scala.github.com/pulls/671","_links":{"self":{"href":"https://api.github.com/repos/scala/scala.github.com/pulls/comments/99270393"},"html":{"href":"https://github.com/scala/scala.github.com/pull/671#discussion_r99270393"},"pull_request":{"href":"https://api.github.com/repos/scala/scala.github.com/pulls/671"}}},"pull_request":{"url":"https://api.github.com/repos/scala/scala.github.com/pulls/671","id":104296982,"html_url":"https://github.com/scala/scala.github.com/pull/671","diff_url":"https://github.com/scala/scala.github.com/pull/671.diff","patch_url":"https://github.com/scala/scala.github.com/pull/671.patch","issue_url":"https://api.github.com/repos/scala/scala.github.com/issues/671","number":671,"state":"open","locked":false,"title":"Add Basics tutorial page","user":{"login":"shogowada","id":10875559,"avatar_url":"https://avatars.githubusercontent.com/u/10875559?v=3","gravatar_id":"","url":"https://api.github.com/users/shogowada","html_url":"https://github.com/shogowada","followers_url":"https://api.github.com/users/shogowada/followers","following_url":"https://api.github.com/users/shogowada/following{/other_user}","gists_url":"https://api.github.com/users/shogowada/gists{/gist_id}","starred_url":"https://api.github.com/users/shogowada/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shogowada/subscriptions","organizations_url":"https://api.github.com/users/shogowada/orgs","repos_url":"https://api.github.com/users/shogowada/repos","events_url":"https://api.github.com/users/shogowada/events{/privacy}","received_events_url":"https://api.github.com/users/shogowada/received_events","type":"User","site_admin":false},"body":"I believe majority of people coming to tutorials are more interested in quick examples than detailed explanations.\r\n\r\nThe current first real tutorial is Unified Types. While it's helpful to know that information, it doesn't give you much insight into how Scala code would look like. I think it can lose interest of readers.\r\n\r\nAlso, while many pages are using features like `object`, `App`, `var`, `val`, etc, what they are isn't necessarily clearly communicated before it's introduced. I think it can throw out readers.\r\n\r\nI created a Basics page to address those concerns. The page is supposed to provide just the most important information out of the most important topics.\r\n\r\nPersonally, for this kind of tutorial, I think it makes more sense to use REPL because it will be easier for writers to make sure what they provide is completely reproducible on reader's machine, and it will be more interesting to readers because it will be easier to interact and play with the code. While I didn't do it because it will be a bigger change if you consider consistency, I think it's worth considering.\r\n\r\nAnother option is to give them link to the [ScalaFiddle](https://scalafiddle.io) so that we can achieve the same goal without readers installing anything on their machine.\r\n\r\nI tried to test it locally, but I am having trouble setting up the build environment (`bundle install` fails because `gem install json -v '1.8.3'` fails, tried multiple solutions found online, and eventually gave up), so I haven't tested it yet, but it looks fine on GitHub.","created_at":"2017-02-02T09:01:31Z","updated_at":"2017-02-03T03:14:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6cff07db96f680e586660acec52f16e8e0aeeea4","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/scala/scala.github.com/pulls/671/commits","review_comments_url":"https://api.github.com/repos/scala/scala.github.com/pulls/671/comments","review_comment_url":"https://api.github.com/repos/scala/scala.github.com/pulls/comments{/number}","comments_url":"https://api.github.com/repos/scala/scala.github.com/issues/671/comments","statuses_url":"https://api.github.com/repos/scala/scala.github.com/statuses/054fb9cc60707cf067fdb20e93c7f5828bc10964","head":{"label":"shogowada:shogowada-patch-1","ref":"shogowada-patch-1","sha":"054fb9cc60707cf067fdb20e93c7f5828bc10964","user":{"login":"shogowada","id":10875559,"avatar_url":"https://avatars.githubusercontent.com/u/10875559?v=3","gravatar_id":"","url":"https://api.github.com/users/shogowada","html_url":"https://github.com/shogowada","followers_url":"https://api.github.com/users/shogowada/followers","following_url":"https://api.github.com/users/shogowada/following{/other_user}","gists_url":"https://api.github.com/users/shogowada/gists{/gist_id}","starred_url":"https://api.github.com/users/shogowada/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shogowada/subscriptions","organizations_url":"https://api.github.com/users/shogowada/orgs","repos_url":"https://api.github.com/users/shogowada/repos","events_url":"https://api.github.com/users/shogowada/events{/privacy}","received_events_url":"https://api.github.com/users/shogowada/received_events","type":"User","site_admin":false},"repo":{"id":80601506,"name":"scala.github.com","full_name":"shogowada/scala.github.com","owner":{"login":"shogowada","id":10875559,"avatar_url":"https://avatars.githubusercontent.com/u/10875559?v=3","gravatar_id":"","url":"https://api.github.com/users/shogowada","html_url":"https://github.com/shogowada","followers_url":"https://api.github.com/users/shogowada/followers","following_url":"https://api.github.com/users/shogowada/following{/other_user}","gists_url":"https://api.github.com/users/shogowada/gists{/gist_id}","starred_url":"https://api.github.com/users/shogowada/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shogowada/subscriptions","organizations_url":"https://api.github.com/users/shogowada/orgs","repos_url":"https://api.github.com/users/shogowada/repos","events_url":"https://api.github.com/users/shogowada/events{/privacy}","received_events_url":"https://api.github.com/users/shogowada/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/shogowada/scala.github.com","description":"The Scala Documentation website","fork":true,"url":"https://api.github.com/repos/shogowada/scala.github.com","forks_url":"https://api.github.com/repos/shogowada/scala.github.com/forks","keys_url":"https://api.github.com/repos/shogowada/scala.github.com/keys{/key_id}","collaborators_url":"https://api.github.com/repos/shogowada/scala.github.com/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/shogowada/scala.github.com/teams","hooks_url":"https://api.github.com/repos/shogowada/scala.github.com/hooks","issue_events_url":"https://api.github.com/repos/shogowada/scala.github.com/issues/events{/number}","events_url":"https://api.github.com/repos/shogowada/scala.github.com/events","assignees_url":"https://api.github.com/repos/shogowada/scala.github.com/assignees{/user}","branches_url":"https://api.github.com/repos/shogowada/scala.github.com/branches{/branch}","tags_url":"https://api.github.com/repos/shogowada/scala.github.com/tags","blobs_url":"https://api.github.com/repos/shogowada/scala.github.com/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/shogowada/scala.github.com/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/shogowada/scala.github.com/git/refs{/sha}","trees_url":"https://api.github.com/repos/shogowada/scala.github.com/git/trees{/sha}","statuses_url":"https://api.github.com/repos/shogowada/scala.github.com/statuses/{sha}","languages_url":"https://api.github.com/repos/shogowada/scala.github.com/languages","stargazers_url":"https://api.github.com/repos/shogowada/scala.github.com/stargazers","contributors_url":"https://api.github.com/repos/shogowada/scala.github.com/contributors","subscribers_url":"https://api.github.com/repos/shogowada/scala.github.com/subscribers","subscription_url":"https://api.github.com/repos/shogowada/scala.github.com/subscription","commits_url":"https://api.github.com/repos/shogowada/scala.github.com/commits{/sha}","git_commits_url":"https://api.github.com/repos/shogowada/scala.github.com/git/commits{/sha}","comments_url":"https://api.github.com/repos/shogowada/scala.github.com/comments{/number}","issue_comment_url":"https://api.github.com/repos/shogowada/scala.github.com/issues/comments{/number}","contents_url":"https://api.github.com/repos/shogowada/scala.github.com/contents/{+path}","compare_url":"https://api.github.com/repos/shogowada/scala.github.com/compare/{base}...{head}","merges_url":"https://api.github.com/repos/shogowada/scala.github.com/merges","archive_url":"https://api.github.com/repos/shogowada/scala.github.com/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/shogowada/scala.github.com/downloads","issues_url":"https://api.github.com/repos/shogowada/scala.github.com/issues{/number}","pulls_url":"https://api.github.com/repos/shogowada/scala.github.com/pulls{/number}","milestones_url":"https://api.github.com/repos/shogowada/scala.github.com/milestones{/number}","notifications_url":"https://api.github.com/repos/shogowada/scala.github.com/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/shogowada/scala.github.com/labels{/name}","releases_url":"https://api.github.com/repos/shogowada/scala.github.com/releases{/id}","deployments_url":"https://api.github.com/repos/shogowada/scala.github.com/deployments","created_at":"2017-02-01T08:27:19Z","updated_at":"2017-02-01T08:27:22Z","pushed_at":"2017-02-02T09:01:22Z","git_url":"git://github.com/shogowada/scala.github.com.git","ssh_url":"git@github.com:shogowada/scala.github.com.git","clone_url":"https://github.com/shogowada/scala.github.com.git","svn_url":"https://github.com/shogowada/scala.github.com","homepage":"http://docs.scala-lang.org","size":4881,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"scala:master","ref":"master","sha":"2333db7a15831142389a8d2837c84060fdd17160","user":{"login":"scala","id":57059,"avatar_url":"https://avatars.githubusercontent.com/u/57059?v=3","gravatar_id":"","url":"https://api.github.com/users/scala","html_url":"https://github.com/scala","followers_url":"https://api.github.com/users/scala/followers","following_url":"https://api.github.com/users/scala/following{/other_user}","gists_url":"https://api.github.com/users/scala/gists{/gist_id}","starred_url":"https://api.github.com/users/scala/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scala/subscriptions","organizations_url":"https://api.github.com/users/scala/orgs","repos_url":"https://api.github.com/users/scala/repos","events_url":"https://api.github.com/users/scala/events{/privacy}","received_events_url":"https://api.github.com/users/scala/received_events","type":"Organization","site_admin":false},"repo":{"id":2577071,"name":"scala.github.com","full_name":"scala/scala.github.com","owner":{"login":"scala","id":57059,"avatar_url":"https://avatars.githubusercontent.com/u/57059?v=3","gravatar_id":"","url":"https://api.github.com/users/scala","html_url":"https://github.com/scala","followers_url":"https://api.github.com/users/scala/followers","following_url":"https://api.github.com/users/scala/following{/other_user}","gists_url":"https://api.github.com/users/scala/gists{/gist_id}","starred_url":"https://api.github.com/users/scala/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scala/subscriptions","organizations_url":"https://api.github.com/users/scala/orgs","repos_url":"https://api.github.com/users/scala/repos","events_url":"https://api.github.com/users/scala/events{/privacy}","received_events_url":"https://api.github.com/users/scala/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/scala/scala.github.com","description":"The Scala Documentation website","fork":false,"url":"https://api.github.com/repos/scala/scala.github.com","forks_url":"https://api.github.com/repos/scala/scala.github.com/forks","keys_url":"https://api.github.com/repos/scala/scala.github.com/keys{/key_id}","collaborators_url":"https://api.github.com/repos/scala/scala.github.com/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/scala/scala.github.com/teams","hooks_url":"https://api.github.com/repos/scala/scala.github.com/hooks","issue_events_url":"https://api.github.com/repos/scala/scala.github.com/issues/events{/number}","events_url":"https://api.github.com/repos/scala/scala.github.com/events","assignees_url":"https://api.github.com/repos/scala/scala.github.com/assignees{/user}","branches_url":"https://api.github.com/repos/scala/scala.github.com/branches{/branch}","tags_url":"https://api.github.com/repos/scala/scala.github.com/tags","blobs_url":"https://api.github.com/repos/scala/scala.github.com/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/scala/scala.github.com/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/scala/scala.github.com/git/refs{/sha}","trees_url":"https://api.github.com/repos/scala/scala.github.com/git/trees{/sha}","statuses_url":"https://api.github.com/repos/scala/scala.github.com/statuses/{sha}","languages_url":"https://api.github.com/repos/scala/scala.github.com/languages","stargazers_url":"https://api.github.com/repos/scala/scala.github.com/stargazers","contributors_url":"https://api.github.com/repos/scala/scala.github.com/contributors","subscribers_url":"https://api.github.com/repos/scala/scala.github.com/subscribers","subscription_url":"https://api.github.com/repos/scala/scala.github.com/subscription","commits_url":"https://api.github.com/repos/scala/scala.github.com/commits{/sha}","git_commits_url":"https://api.github.com/repos/scala/scala.github.com/git/commits{/sha}","comments_url":"https://api.github.com/repos/scala/scala.github.com/comments{/number}","issue_comment_url":"https://api.github.com/repos/scala/scala.github.com/issues/comments{/number}","contents_url":"https://api.github.com/repos/scala/scala.github.com/contents/{+path}","compare_url":"https://api.github.com/repos/scala/scala.github.com/compare/{base}...{head}","merges_url":"https://api.github.com/repos/scala/scala.github.com/merges","archive_url":"https://api.github.com/repos/scala/scala.github.com/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/scala/scala.github.com/downloads","issues_url":"https://api.github.com/repos/scala/scala.github.com/issues{/number}","pulls_url":"https://api.github.com/repos/scala/scala.github.com/pulls{/number}","milestones_url":"https://api.github.com/repos/scala/scala.github.com/milestones{/number}","notifications_url":"https://api.github.com/repos/scala/scala.github.com/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/scala/scala.github.com/labels{/name}","releases_url":"https://api.github.com/repos/scala/scala.github.com/releases{/id}","deployments_url":"https://api.github.com/repos/scala/scala.github.com/deployments","created_at":"2011-10-14T15:37:14Z","updated_at":"2017-02-02T20:33:14Z","pushed_at":"2017-02-02T09:01:32Z","git_url":"git://github.com/scala/scala.github.com.git","ssh_url":"git@github.com:scala/scala.github.com.git","clone_url":"https://github.com/scala/scala.github.com.git","svn_url":"https://github.com/scala/scala.github.com","homepage":"http://docs.scala-lang.org","size":4884,"stargazers_count":262,"watchers_count":262,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":294,"mirror_url":null,"open_issues_count":42,"forks":294,"open_issues":42,"watchers":262,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scala/scala.github.com/pulls/671"},"html":{"href":"https://github.com/scala/scala.github.com/pull/671"},"issue":{"href":"https://api.github.com/repos/scala/scala.github.com/issues/671"},"comments":{"href":"https://api.github.com/repos/scala/scala.github.com/issues/671/comments"},"review_comments":{"href":"https://api.github.com/repos/scala/scala.github.com/pulls/671/comments"},"review_comment":{"href":"https://api.github.com/repos/scala/scala.github.com/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/scala/scala.github.com/pulls/671/commits"},"statuses":{"href":"https://api.github.com/repos/scala/scala.github.com/statuses/054fb9cc60707cf067fdb20e93c7f5828bc10964"}}}}
{"actor":{"display_login":"tpolecat"}}