{"componentChunkName":"component---src-templates-lesson-js","path":"/phoenix-chat/introduction","result":{"data":{"mdx":{"body":"function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }\n\nfunction _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }\n\nfunction _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }\n\n/* @jsx mdx */\nvar _frontmatter = {\n  \"title\": \"Introduction\",\n  \"order\": 0,\n  \"free\": true,\n  \"active\": true,\n  \"tech\": null\n};\n\nvar makeShortcode = function makeShortcode(name) {\n  return function MDXDefaultShortcode(props) {\n    console.warn(\"Component \" + name + \" was not imported, exported, or provided by MDXProvider as global scope\");\n    return mdx(\"div\", props);\n  };\n};\n\nvar layoutProps = {\n  _frontmatter: _frontmatter\n};\nvar MDXLayout = \"wrapper\";\nreturn function MDXContent(_ref) {\n  var components = _ref.components,\n      props = _objectWithoutProperties(_ref, [\"components\"]);\n\n  return mdx(MDXLayout, _extends({}, layoutProps, props, {\n    components: components,\n    mdxType: \"MDXLayout\"\n  }), mdx(\"h1\", null, \"Introduction\"), mdx(\"ul\", null, mdx(\"li\", {\n    \"parentName\": \"ul\"\n  }, \"What is Phoenix?\"), mdx(\"li\", {\n    \"parentName\": \"ul\"\n  }, \"What is React?\"), mdx(\"li\", {\n    \"parentName\": \"ul\"\n  }, \"What will be covered?\"), mdx(\"li\", {\n    \"parentName\": \"ul\"\n  }, \"What are some alternatives?\")), mdx(\"p\", null, \"As any experienced developer knows, scaling is not a trivial problem. In fact, if your product is successful, building the app is often the easiest part of the process.\"), mdx(\"p\", null, \"Scaling is more than just handling concurrent connections or a boat-load of simultaneous requests. It also means dealing with a large team pushing code at the same time, building architecture that makes it easy to change pieces of the app without breaking everything, and knowing about important DevOps concepts that are generally ignored by most tutorials.\"), mdx(\"p\", null, \"Scaling problems are much harder to predict, track down, and prevent if you do not consider them from the outset of your project. You need to be aware of every inefficiency, ensure actions from different customers do not conflict, grow your database, handle errors, tolerate server failures, among a litany of other issues that a smaller app simply does not need to consider.\"), mdx(\"p\", null, \"Developers who have to deal with legacy code on a regular basis know the feeling of staring at a codebase that looks like a Frankenstein monster of outdated technologies and an assortment of hacks that could fall apart at any moment. Refactoring would take too much time, so you just continue to pile onto the monster and pretend that everything is fine.\"), mdx(\"p\", null, mdx(\"img\", {\n    \"src\": \"https://raw.githubusercontent.com/LearnPhoenix/graphics/master/stick_prototyping.png\",\n    \"alt\": \"prototyping\",\n    \"parentName\": \"p\"\n  })), mdx(\"p\", null, \"So why not just build your app in a framework that is designed from the ground up to easily handle your scaling concerns, refactors without server shutdowns, and comes in an easily-understood syntax? Enter Phoenix.\"), mdx(\"h2\", null, \"What is Phoenix?\"), mdx(\"p\", null, \"Phoenix is a web framework built with \", mdx(\"a\", {\n    \"href\": \"http://elixir-lang.org/\",\n    \"parentName\": \"p\"\n  }, \"Elixir\"), \" that is able to leverage the \", mdx(\"a\", {\n    \"href\": \"http://www.wired.com/2015/09/whatsapp-serves-900-million-users-50-engineers/\",\n    \"parentName\": \"p\"\n  }, \"insanely powerful Erlang VM\"), \" gives you the ability to handle millions of concurrent connections, while also remaining fault-tolerant and easy to implement.\"), mdx(\"p\", null, \"To give you a real comparison, here is how Phoenix performs compared to other popular frameworks (data from \", mdx(\"a\", {\n    \"href\": \"https://github.com/mroth/phoenix-showdown\",\n    \"parentName\": \"p\"\n  }, \"mroth\"), \"):\"), mdx(\"p\", null, mdx(\"img\", {\n    \"src\": \"https://raw.githubusercontent.com/LearnPhoenix/graphics/master/performance.png\",\n    \"alt\": \"performance\",\n    \"parentName\": \"p\"\n  })), mdx(\"p\", null, \"This is the same underlying technology that WhatsApp uses and one of the reasons Facebook paid \\\\$19b for them. Check out this article in Wired appropriately titled \", mdx(\"a\", {\n    \"href\": \"http://www.wired.com/2015/09/whatsapp-serves-900-million-users-50-engineers/\",\n    \"parentName\": \"p\"\n  }, \"Why WhatsApp Only Needs 50 Engineers for Its 900M Users\"), \". As you might guess, it has to do with Erlang.\"), mdx(\"p\", null, \"Phoenix uses the programming language Elixir, which is a \", mdx(\"a\", {\n    \"href\": \"https://medium.com/@chetcorcos/functional-programming-for-javascript-people-1915d8775504\",\n    \"parentName\": \"p\"\n  }, \"functional programming language\"), \" built on Erlang. The syntax is very similar to \", mdx(\"a\", {\n    \"href\": \"https://www.ruby-lang.org/en/\",\n    \"parentName\": \"p\"\n  }, \"Ruby\"), \" and most programmers find it easy to understand. The hardest part is not the language itself, but wrapping one's head around the concepts of functional programming.\"), mdx(\"p\", null, \"The basic syntax for Elixir looks like this:\"), mdx(\"pre\", null, mdx(\"code\", {\n    \"className\": \"language-elixir\",\n    \"parentName\": \"pre\"\n  }, \"defmodule Fib do\\n  def fib(0) do 0 end\\n  def fib(1) do 1 end\\n  def fib(n) do fib(n-1) + fib(n-2) end\\nend\\n\")), mdx(\"h2\", null, \"What is React\"), mdx(\"p\", null, \"React is the \\\"V\\\" in \\\"MVC\\\" (Model View Controller). It is all JavaScript and it has quickly become the new standard for frontends. Rather than using a \", mdx(\"a\", {\n    \"href\": \"https://en.wikipedia.org/wiki/Markup_language\",\n    \"parentName\": \"p\"\n  }, \"markup language\"), \" like HTML to render the DOM, React creates each element in the DOM with a function and creates a \\\"virtual DOM\\\" which it can use to compare against the current version of the DOM and render only the smallest necessary amount of information. If this sounds complicated, don't worry. React does all of this behind the scenes, so all you have to do is write JavaScript.\"), mdx(\"p\", null, \"This roundabout approach might seem like overkill, but it leads to more efficient rendering, better code maintainability, and the advantage of being able to write everything in a syntax that is more coherent than a markup language: JavaScript.\"), mdx(\"p\", null, \"React has become immensely popular, it is supported by Facebook, and it's already used in production in countless major websites and apps.\"), mdx(\"p\", null, \"The basic syntax for JavaScript is:\"), mdx(\"pre\", null, mdx(\"code\", {\n    \"className\": \"language-js\",\n    \"parentName\": \"pre\"\n  }, \"function fibonacci(n) {\\n  if (n < 2) {\\n    return n\\n  } else {\\n    return fibonacci(n - 2) + fibonacci(n - 1)\\n  }\\n}\\n\")), mdx(\"h2\", null, \"What will be covered?\"), mdx(\"p\", null, \"This set of lessons is intended for people with at least some experience programming. An ideal candidate for this series is someone who just finished a coding bootcamp and wants to start learning how to write production-ready code. If you're a Ruby on Rails developer, or if you have experience with another framework, you should have no problem picking this up.\"), mdx(\"p\", null, \"It would be ideal for someone with experience in functional programming, but this is not necessary; we will go through the fundamental concepts of functional programming.\"), mdx(\"p\", null, \"We will cover some of the basics of Elixir and we will touch on Erlang when necessary. For more detailed tutorials on Elixir, check out \", mdx(\"a\", {\n    \"href\": \"elixirsips.com\",\n    \"parentName\": \"p\"\n  }, \"ElixirSips.com\"), \" and \", mdx(\"a\", {\n    \"href\": \"elixirschool.com\",\n    \"parentName\": \"p\"\n  }, \"ElixirSchool\"), \", which will teach you a lot more about the language.\"), mdx(\"p\", null, \"On the frontend, we will cover the basics of React and Redux, but a deeper knowledge of React will be very useful. The \", mdx(\"a\", {\n    \"href\": \"egghead.io\",\n    \"parentName\": \"p\"\n  }, \"egghead.io\"), \" tutorials on React, Redux, and React Native are really good if you're looking for additional resources.\"), mdx(\"p\", null, \"We will cover some of the basics of styling and we will use Sass as our preprocessor. We will also be using \", mdx(\"a\", {\n    \"href\": \"css-modules\",\n    \"parentName\": \"p\"\n  }, \"CSS Modules\"), \" to make our CSS more maintainable and modular.\"), mdx(\"p\", null, mdx(\"strong\", {\n    \"parentName\": \"p\"\n  }, \"This is not an intro-level tutorial.\"), \" We will not cover the basics of programming. You do not need to be an expert, but you should at least know what a \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"function\"), \" is and generally how to use them in at least one language. You should also know what a \", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"library\"), \" (\", mdx(\"a\", {\n    \"href\": \"lodash.com\",\n    \"parentName\": \"p\"\n  }, \"Lodash\"), \", \", mdx(\"a\", {\n    \"href\": \"getboostrap.com\",\n    \"parentName\": \"p\"\n  }, \"Bootstrap\"), \", etc) is and have at least some idea of how to use one.\"), mdx(\"p\", null, \"If you are totally new to programming, start with something like \", mdx(\"a\", {\n    \"href\": \"http://codeschool.com\",\n    \"parentName\": \"p\"\n  }, \"CodeSchool\"), \". HTML and CSS is probably the easiest place to start, followed by JavaScript and Ruby on Rails. Once you have the basics down, come back and sign up.\"), mdx(\"h2\", null, \"What is the ideal type of app for this framework?\"), mdx(\"p\", null, \"Phoenix is ideal for highly concurrent apps, meaning, apps that have a lot of things happening at the same time. For example, a popular messaging app might have a few million people using it at any given time, and each of those users will expect to receive real-time updates when a message is sent or received.\"), mdx(\"p\", null, \"This is not to say that Phoenix does not perform well for apps that do not demand concurrency. Its fault-tolerance alone makes it ideal for most environments. You lose very little in the way of developer efficiency for a final product that is significantly better.\"), mdx(\"p\", null, \"That said, for a small hackathon-type app, Phoenix is probably overkill. A self-contained JavaScript framework such as Meteor.js or Feather.js are hard to beat for this type of app.\"), mdx(\"p\", null, \"There are also languages other than Elixir/Erlang that are better suited for large-scale computation. So if you foresee a lot of number crunching or machine learning in your future, you might want to consider \", mdx(\"a\", {\n    \"href\": \"http://www.oracle.com/technetwork/java/index-138747.html\",\n    \"parentName\": \"p\"\n  }, \"Java\"), \", \", mdx(\"a\", {\n    \"href\": \"https://www.python.org/\",\n    \"parentName\": \"p\"\n  }, \"Python\"), \", or \", mdx(\"a\", {\n    \"href\": \"https://www.r-project.org/\",\n    \"parentName\": \"p\"\n  }, \"R\"), \".\"), mdx(\"h2\", null, \"What are some alternatives?\"), mdx(\"p\", null, \"You can use Phoenix for both the frontend and the backend using Elixir's builtin markup language. If you choose to go that route, check out the book \", mdx(\"a\", {\n    \"href\": \"https://pragprog.com/book/phoenix/programming-phoenix\",\n    \"parentName\": \"p\"\n  }, \"Programming Phoenix\"), \".\"), mdx(\"p\", null, \"If you're looking to make a quick prototype and you're proficient in JavaScript Meteor.js and Feathers.js are excellent options.\"), mdx(\"p\", null, \"Ruby on Rails is also a safe bet and is probably the default choice for the majority of startups as of 2016. There are a nearly-endless number of resources Rails. A good place to start is \", mdx(\"a\", {\n    \"href\": \"http://codeschool.com\",\n    \"parentName\": \"p\"\n  }, \"CodeSchool\"), \" if you're new to the framework.\"), mdx(\"p\", null, \"There are hundreds, if not thousands of options. If you need something more specific than the options listed above, you probably already know what you need and this section has not been especially useful to you.\"), mdx(\"h2\", null, \"General formatting\"), mdx(\"p\", null, \"Each lesson takes you through the process of building an app with varying levels of complexity. We will also generally use different technologies for each app as the landscape evolves. For example, this app will use React and Redux, while a future app may use \", mdx(\"a\", {\n    \"href\": \"http://cycle.js.org/\",\n    \"parentName\": \"p\"\n  }, \"Cycle.js\"), \", React Native, or \", mdx(\"a\", {\n    \"href\": \"http://elm-lang.org/\",\n    \"parentName\": \"p\"\n  }, \"Elm\"), \".\"), mdx(\"p\", null, \"In the event you have a bug to report, please post an issue in the Github repository. The Node ecosystem in particular moves very quickly and it is likely some pieces of this tutorial will become outdated in a matter of weeks. If the question is more generally about Phoenix, React, Elixir, et al, please post the question on \", mdx(\"a\", {\n    \"href\": \"stackoverflow.com\",\n    \"parentName\": \"p\"\n  }, \"StackOverflow\"), \".\"), mdx(\"p\", null, \"Code written in codeblocks, such as the code below, shows you the code being added, removed, or changed. Ellipses (\", mdx(\"inlineCode\", {\n    \"parentName\": \"p\"\n  }, \"...\"), \") are often used in place of code that is being omitted for reasons of brevity.\"), mdx(\"pre\", null, mdx(\"code\", {\n    \"className\": \"language-js\",\n    \"parentName\": \"pre\"\n  }, \"class LessonShow extends React.Component {\\n\\n  ...\\n\\n}\\n\")), mdx(\"p\", null, \"Command line inputs will look like the example code below. The command line inputs assume you are using a Mac. If you're on a Linux machine, you probably already know what you're doing and it will be similar.\"), mdx(\"pre\", null, mdx(\"code\", {\n    \"className\": \"language-bash\",\n    \"parentName\": \"pre\"\n  }, \"$ cd ~/directory/name\\n\")), mdx(\"h2\", null, \"Contact\"), mdx(\"p\", null, \"Feel free to contact us at any time with comments or questions at \", mdx(\"a\", {\n    \"href\": \"mailto:info@learnphoenix.io\",\n    \"parentName\": \"p\"\n  }, \"info@learnphoenix.io\"), \".\"), mdx(\"p\", null, \"A special thanks to \", mdx(\"a\", {\n    \"href\": \"https://github.com/knewter\",\n    \"parentName\": \"p\"\n  }, \"Josh Adams\"), \", \", mdx(\"a\", {\n    \"href\": \"https://github.com/doomspork\",\n    \"parentName\": \"p\"\n  }, \"Sean Callan\"), \", and \", mdx(\"a\", {\n    \"href\": \"https://github.com/ryanswapp\",\n    \"parentName\": \"p\"\n  }, \"Ryan Swapp\"), \" for all your help in making this possible.\"));\n}\n;\nMDXContent.isMDXComponent = true;","excerpt":"Introduction What is Phoenix? What is React? What will be covered? What are some alternatives? As any experienced developer knows, scaling…","frontmatter":{"title":"Introduction","order":0,"active":true,"free":true,"tech":null}}},"pageContext":{"slug":"introduction","prevNode":null,"nextNode":{"frontmatter":{"title":"Installing Phoenix and React","active":true,"free":true,"order":1,"tech":["phoenix","react"]},"fields":{"slug":"installing-phoenix-and-react"}}}},"staticQueryHashes":["1723017916"]}