<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Daniel Hitchcock on Medium]]></title>
        <description><![CDATA[Stories by Daniel Hitchcock on Medium]]></description>
        <link>https://medium.com/@daniel.s.hitchcock?source=rss-102134f9432b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*7oiO4Ou9zuvkEtOK.jpg</url>
            <title>Stories by Daniel Hitchcock on Medium</title>
            <link>https://medium.com/@daniel.s.hitchcock?source=rss-102134f9432b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 04:19:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@daniel.s.hitchcock/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Cowboy Coding to Professional Developer]]></title>
            <link>https://medium.com/analytics-vidhya/cowboy-coding-to-professional-developer-f271d5627439?source=rss-102134f9432b------2</link>
            <guid isPermaLink="false">https://medium.com/p/f271d5627439</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[hobby]]></category>
            <category><![CDATA[beginner]]></category>
            <dc:creator><![CDATA[Daniel Hitchcock]]></dc:creator>
            <pubDate>Thu, 27 Feb 2020 02:37:42 GMT</pubDate>
            <atom:updated>2020-03-06T08:15:57.394Z</atom:updated>
            <content:encoded><![CDATA[<h4>What I would have told myself when I was a hobbyist</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/1*ZbAcsMjY8YvZ_Q2h98HY8Q.png" /></figure><p>It was only 8 months ago that I was hacking together scripts in my spare time. I didn’t know any of the formal programming etiquette, but I was my own person and got things done.</p><p>I called this Cowboy coding.</p><p>Once I got a job as a professional developer, I learned what I was missing out on. These are the things I would I could have told myself, as well as the advice I give to anyone who is dabbling in software development.</p><h3><strong>1. Use a Real IDE</strong></h3><p>If you are a Python user and are still using IDLE, immediately download <a href="https://code.visualstudio.com/">VSCode</a>. Or <a href="https://www.jetbrains.com/pycharm/">PyCharm</a>. Or <a href="https://atom.io/">Atom</a>. They are free, and offer a myriad of features to help you. If you program in another language, do a little research to find out what the best IDE is. I currently use PyCharm for Python (and Jupyter Notebook), and VSCode for JavaScript, HTML, TypeScript, Go, and pretty much anything else.</p><p>Using such a developed, high tech tool might feel like overkill for your 10 line hello-world test scripts, but the moment you begin to develop multi-file projects, or need to jump around between them, or experiment with different environments, you’ll understand why a sophisticated IDE is so important.</p><ol><li><strong>Support For Multi-File Projects</strong> — Before you know it, your projects will no longer be simple single file apps. It’s great to manage them together instead of clicking through windows.</li><li><strong>Support For Multiple Languages</strong> — You will learn other programming languages, there’s no way of getting around it. And as your projects become more complex, you’ll suddenly find they’re made of more than one language. In VSCode, I can easily hop between Python, Go, and Javascript.</li><li><strong>Plug-Ins </strong>— There are huge communities behind these IDEs, developing open source plugins, trying to make all of our lives easier. There are plugins for Code Formatting (see below), Git integration, testing, viewing MarkDown files or HTML; if there is something you need, someone has probably created a plugin for it.</li><li><strong>Introspection </strong>— I can highlight a function in my program and it will tell me its arguments. I can hit ‘tab’, and my IDE will autocomplete what I was typing, or at least give great suggestions. I can also click on a term, and it will take me to where that variable/function was declared, or perhaps show me everywhere it is used.</li></ol><h3><strong>2. Use a Code Formatter (and Linter)</strong></h3><p>I cannot stress this enough. **<strong>Use a Code Formatter!**</strong> This is not cheating! Using a code formatter does not make you less of a programmer; it makes you a smart person who wants to get stuff down and look good in the process. Less time spent formatting means more time for programming.</p><p>If you are using Python, I highly recommend <a href="https://black.readthedocs.io/en/stable/">Black</a>. It can be added to any real IDE. It can even be invoked every time you save file. For Javascript/Typescript, there is Prettier. For Go, well, Go has its own built in gofmt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*14NBJ9LChlAyXFTGrJ0NNg.gif" /><figcaption>So satisfying.</figcaption></figure><p>Similarly, you need to install a linter. A linter lets you know if you have variables mistyped, or unused imports, any any other common coding errors. PyCharm comes installed with one, but I would recommend adding <a href="https://www.pylint.org/">Pylint</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/867/1*ky07hnfkYbEsMf70et94jg.png" /><figcaption>“Unnecessary use of a comprehension”? — I’ll be the judge of that.</figcaption></figure><h3><strong>3. Control Your Environment</strong></h3><p>Let’s again say you’re a Python developer. What version of Python are you using? If you are like I was, your response is probably “Um, 3-point… something. What’s it matter?” The correct response should be “For which project?”</p><h4><strong>Version Conflicts in Your Projects</strong></h4><p>Let’s say you had a really cool project called <strong>Old_Project</strong>. You start working on <strong>New_Project</strong>, and quickly find out that a new feature you need isn’t available with your version of Python or some library. So you upgrade, and what happens?</p><p><strong>Old_Project</strong> no longer works.</p><p>And why should it? It never agreed to work with all this new fangled software you just upgraded to. So what’s the solution?</p><p>Have your own environments for <strong>New_Project</strong> or <strong>Old_Project</strong>. Heck, have a different environment for each project if you like!</p><h4><strong>Step 1: Get An Environment Manager (Conda for Python)</strong></h4><p>Conda makes this incredibly easy in Python, and other languages have similar tools. If you don’t have Conda, download <a href="https://www.anaconda.com/distribution/#download-section">Anaconda</a> or <a href="https://docs.conda.io/en/latest/miniconda.html">Miniconda</a> and use it as your default Python distribution.</p><p>For creating a new environment, simply type conda create -n cool-environment , then conda activate cool-environment, and you’re there. When your done, conda deactivate. You can also set this environment in PyCharm project settings if that’s your thing.</p><h4><strong>Step 2: Use a Makefile</strong></h4><p>Wanna’ really step up your game? Create a file in every one of your projects entitled environment.ymland invoke it with a Makefile. environment.yml holds your environment information, and Makefile has the means to run this script. This offers incredibly tight control of your environment and prepares your project to be run on various systems.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*Bup1MHypulhck42cBakqNg.png" /><figcaption>Two little files, and worry free environment support! Look at those cool icons.</figcaption></figure><p>Here’s an environment.yml example:</p><pre>name: old_project<br> channels:<br> — defaults<br> dependencies:<br> — python=3.6<br> — pandas=0.25</pre><p>This could be invoked by typing conda env create -f environment.yml. But Makefiles are the way to go. Here’s a very basic example:</p><pre>setup: env-setup</pre><pre>remove: env-remove</pre><pre>env-setup:<br>    conda env create -f environment.yml</pre><pre>env-remove:<br>    conda env remove -n old_project</pre><p>When you type make setup, this builds a conda environment under tight version control. If you need to remove it, simply type make remove. Each project can have its own environment.yml and Makefile!</p><p>Here’s an action shot in Pycharm. (Note: how each file has its own syntax highlighted — i.e. Use a real IDE!)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/889/1*DACK2S1WVfrIxrxFGYNeYQ.gif" /></figure><p>Anyone who downloads your project can instantly create a compatible environment!</p><h3><strong>4. Drop Dropbox; Get Git</strong></h3><h4><strong>Dropbox is not version control</strong></h4><p>Yes, I happily used Dropbox to keep my files safe and synced for 4 years. There were a few minor inconveniences, like resetting my environment every time I went from Desktop to Laptop, or dealing with conflicted copies, but it worked..</p><p>But would you know? — There is a program developed to address this specific issue!</p><p>Git, when used with a remote repository, accomplishes everything you’re using Dropbox for right now. <strong>And substantially more.</strong></p><h4><strong>Keep Your Project Safe With GitHub</strong></h4><p>GitHub is so kind as to host Git projects for free! You can have an unlimited number of public repos and 3 private ones. If you’re using Git, you simply need to push your changes to the remote repo. You don’t even need to use “complicated” git commands: just commit your changes and push. When you switch workstations, a quick “git pull” and now you can begin right where you left off.</p><p><strong>If you ever apply for software development jobs, your GitHub repo is a perfect way to advertise yourself</strong>. Hiring managers will definitely be looking at this, and you should be proud to show it . Put it on your resume, show your enthusiasm!</p><p>Back to Git — It’s not just a glorified file sharing platform…</p><h4><strong>A Case Study With Branches — Add a New Feature</strong></h4><p>Take, for example, a situation where you need to add a Cool New Feature to your program. Only problem is this will take a week to implement, and you need your program function <strong>tomorrow</strong>.</p><p>In the DropBox world, you would have to copy and paste your entire directory tree and start hacking… now you have two directories taking up space, and to merge your changes in, you need to do some awkward copy-paste acrobatics. This is obviously an anti-pattern.</p><p>In the Git world, you can make branches of your code and effortlessly hop between them. You could type git checkout -b cool_new_feature. This will create a new branch of your code called “cool_new_feature”, a whole virtual playground to experiment with your program. IDEs are all prepared for this, and they happily update your code when a new branch is invoked. If you need to revert to your functioning program, commit your changes and simply type git checkout master. Boom — functioning code! Once you’re ready to start working on your feature, type git checkout cool_new_feature and pick up right where you left off. Once you’re finished, merge into master by typing git checkout master, git merge cool_new_feature.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/729/1*4_ozAVJc2ZcJJiU6eJnMpw.gif" /></figure><h4><strong>Simplified Git Workflows</strong></h4><p>If this sounds complicated, there are workflows on how/when to branch and conventions for naming. My group uses <a href="https://www.atlassian.com/git/tutorials/comparing-workflows/gitflow-workflow">Git Flow</a>. But this is overkill for small projects, and I would recommend <a href="https://guides.github.com/introduction/flow/">GitHub Flow</a> for the hobbyist. If you’re the only person working on a project, 95% of your Git commands will be git commit, git branch &lt;new branch&gt; , git checkout &lt;branch&gt;, git push, git pull , git merge &lt;branch&gt;.</p><h4><strong>Software Development Process</strong></h4><p>Also, take this as an opportunity to learn about software development in general. Each branch should only accomplish one goal, be it a new feature, a bugfix, or some other chore.</p><h4><strong>I promise you: You will not regret learning Git!</strong></h4><h3><strong>6. Don’t Think You’re Not Good Enough</strong></h3><p>I used to have this mindset that anything I wrote, someone else could do it way better. This even used to prevent my from writing tools which turned out to be quite successful, thinking it would be a disservice to push my inferior product!</p><h4><strong>Don’t Sweat the Complicated Stuff</strong></h4><p>Do you know the difference between a Class attribute and an Instance attribute? “Python Path” vs “System Path”? Do you know how to cythonize a async decorated generator in a recursive function?</p><p>A lot of developers would answer “No” to these questions too. And that’s fine.</p><p>It’s great to be mindful of program features, but if you don’t need to use them, don’t worry about it. It doesn’t make you an inferior programmer because you use a Dictionary where everyone else tries to create a Class (some might argue it would make you a better programmer).</p><p>If you’re writing programs that solve your needs, that means you are good enough. That doesn’t mean there isn’t a better way to do it, of course, which brings me to my next point:</p><h4><strong>Find a Friend</strong></h4><p>The biggest difference between me now and 8 months ago is that I’m surrounded by 7 other professional developers. We all have strengths and weaknesses and some of us are more experienced, <strong>but none of us know everything that the remaining six combined do</strong>.</p><p>I have seven people I can go to for questions. Seven people who can review my work. Seven people creating code masterpieces that I can read, and think “Oh, interesting..” (and not always sarcastically). I’m no longer stuck spinning my wheels on trivial issues that someone else can easily solve. I can ask them.</p><h4><strong>It’s way better than being shamed on Stack Overflow.</strong></h4><p>Find some friends and get involved. Are there two of you developing the same/similar projects? Start an Agile group! Even if neither of you are particularly experienced, there is a lot of learning that can happen.</p><h3>In Conclusion…</h3><h4><strong>Programming is NOT Only About Writing Code</strong></h4><p>How much actual code did I show in this article? Almost none.</p><p>I used to think to be a better programmer, I would need to learn the nitty-gritty of Python. But most of my growth as a developer hasn’t been about gaining an expert knowledge of Python, but about everything surrounding it. Things like learning REST, AWS, or just how to structure a multi-piece projects.</p><p>I also didn’t think I stood a chance when I was applying to software development jobs, but here I am. If you are passionate about coding, there is a place for you.</p><h4><strong>Some Other Things</strong></h4><p>The suggestions I listed above are universal for any programming language, and it is worth your effort to study them in depth. <strong>It won’t be wasted time.</strong></p><p>Some other small suggestions:</p><ul><li>Make Unittests. I recommend PyTest, and bonus points for invoking it with your Makefile (make test).</li><li>Get comfortable with the command line!</li><li>Learn another programming language! Is you favorite dynamically typed? Learn a static typed language (like Go!). It will change how you think about programming, and ultimately make you better.</li><li>Learn basic web stuff and REST. Learn how to make a simple website and a REST back-end. A little goes a long way.</li></ul><h3><strong>Some Useful Links</strong></h3><ul><li><a href="https://try.github.io/">Git Tutorials</a></li><li><a href="https://medium.com/@marcobelo/setting-up-python-black-on-visual-studio-code-5318eba4cd00">Install Black on VSCode</a></li><li><a href="https://black.readthedocs.io/en/stable/editor_integration.html">Install Black on Pycharm</a></li><li><a href="https://www.jetbrains.com/help/pycharm/pytest.html">PyTest on Pycharm</a></li></ul><h4>Image credits:</h4><p>Cowboy hat: <a href="https://www.1001freedownloads.com/free-clipart/cowboy-hat-2">https://www.1001freedownloads.com/free-clipart/cowboy-hat-2</a></p><p>Tie: <a href="https://www.1001freedownloads.com/free-clipart/necktie">https://www.1001freedownloads.com/free-clipart/necktie</a></p><p>Gifs created with: <a href="https://www.screentogif.com/">https://www.screentogif.com/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f271d5627439" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/cowboy-coding-to-professional-developer-f271d5627439">Cowboy Coding to Professional Developer</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Gentle Intro to Angular for Frustrated Python Devs]]></title>
            <link>https://medium.com/analytics-vidhya/gentle-intro-to-angular-for-frustrated-python-devs-9eb584c98463?source=rss-102134f9432b------2</link>
            <guid isPermaLink="false">https://medium.com/p/9eb584c98463</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Daniel Hitchcock]]></dc:creator>
            <pubDate>Sat, 08 Feb 2020 22:50:21 GMT</pubDate>
            <atom:updated>2020-02-13T04:21:05.255Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1eGAciv4w3HQiw_M50WKeg.png" /></figure><p><em>Being new to Angular, I still have pretty fresh eyes on my experience with the learning curve. As a Python Developer with object-oriented experience, these are the things I wish someone would have told me.</em></p><h4>Your First (and Potentially Last) Angular App</h4><p>Do you remember writing your first Python program? It was probably a joyous moment involving the creation of simple one-liner called hello.py:</p><pre>print(&quot;Hello World!&quot;)</pre><p>So simple! One file, one line, and it runs on any version of Python 3.</p><p>Now, for your first Angular app… you’re familiar with HTML, JavaScript, and Typescript, and you have your comfy socks and 2 hours of free time. After glancing at some tutorials, you probably decided to dive right into the deep end by typing ng new. If you’ve used React in the past, you were probably expecting a self-contained .js/.ts file ready to be served by your favorite back-end template manager.</p><p>Go on, type ng new my-first-app. I dare you.</p><p>After answering a few innocuous questions and pressing enter, your console explodes into a fury of compilation and file creation. 10 seconds and 31 files later, you have your “Hello World!” Angular app created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*nSz6oAiUJLlBIrcaviPvJQ.png" /><figcaption>One does not simply “dabble” in Angular</figcaption></figure><p>Sadly, this is where most tutorials begin and enthusiasm ends.</p><h4>Your Second First App</h4><p>Angular is a behemoth. It has a built in test suite, git repo, linter config files, Angular prod/dev setup files, and even prepares your Node environment. Maybe future versions will do your taxes. Later down the road this all might be super-great, but for someone who just wants a Hello World example this can be an anxiety inducing affair.</p><p>Fortunately, most of this stuff can be ignored. Some of it can even be removed.</p><p>For something a little more lightweight, try ng new my-second-app --minimal --skip-git . This constructs our new project without testing, git, and keeps the template .html files embedded in the actual script. It’s not quite “barebones,” but I hope by now you know what Angular isn’t a “barebones” affair.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*750ZMLBeE5bOq6bydijCmw.png" /><figcaption>*Ok I know what some of them do.</figcaption></figure><p>Using the power of ignoring things, our app is now only 2 files!: app.module.ts and app.component.ts.(And if we really wanted to, we could combine them). As for the others files, don’t worry about them for the time being. They’re there for a reason. You’ll find that Angular is like a Flask or Django or Kivy app, or any other framework that executed by some mysterious back end forces. You define the functions and classes, but something else runs it. The files we’re ignoring control that behavior.</p><h4>Simple App Structure</h4><h4>app.module.ts — Project Definitions</h4><p>Most general purpose programming languages have a similar format. Some imports, some class declarations, and some functions. Angular is no exception; if you’ve done object oriented programming in Python or have worked with framework like Flask, this should start to look familiar to you.</p><p>Take a look at app.module.ts, which defines the structure of our entire app:</p><pre>import { BrowserModule } from &#39;@angular/platform-browser&#39;;<br>import { NgModule } from &#39;@angular/core&#39;;</pre><pre>import { AppComponent } from &#39;./app.component&#39;;</pre><pre>@NgModule(<br>  {<br>    declarations: [AppComponent],<br>    imports: [BrowserModule],<br>    providers: [],<br>    bootstrap:[AppComponent]<br>  }<br>)<br>export class AppModule { }</pre><p>No HMTL here, just some imports and an empty (but decorated) class. Going over the imports:</p><ol><li>BrowserModule — I don’t know what this does, but so far I don’t need to.</li><li>NgModule — This is the decorator used in the code, and part of Angular core. Much like Flask in Python, decorators are how the real magic works in Angular. This tells Angular that this the starting point of your app.</li><li>AppComponent — This is your app! Or, it’s a component in your app at least. Like app.module.ts, it’s located in the /src/app directory. It provides our AppComponent class, which we will modify to change our website.</li></ol><p>Next in app.module.ts is some real code.</p><p>This looks like a mess (at first), but on closer examination as least it’s familiar. The class itself doesn’t do anything. The decorator @NgModule turns this empty class into an Angular Module and defines declarations , imports, providers, and bootstrap. Decorators in TypeScript are pretty similar to those in Python; they simply modify the object/function they’re decorating. In this case, the decorator adds some Angular-specific properties and makes it look like an Angular Module. It’s possible to write this <a href="https://embed.plnkr.co/on3W4t/">without decorators</a>, but I think this is much cleaner. Why Angular chose decorators over inheritance, or instances of their own predefined classes? Who knows. Anyways:</p><ol><li>declarations — This is a list of every component in our Angular app. We only have the one right now.</li><li>imports — These are the imports or packages required by the components.</li><li>providers — These are classes which Angular will prepare and inject into components. In the “Bonus: Constructors” section of this article, CookieService would be included as a provider.</li><li>bootstrap — The entry point for your app. In this case, it’s AppComponent as defined in app.component.ts.</li></ol><p>app.module.ts doesn’t have anything too spectacular; primarily it defines the scope of our project. For the actual website, take a look at app.component.ts.</p><h4>app.component.ts — Your Website</h4><pre>import { Component } from &#39;@angular/core&#39;;</pre><pre>@Component(<br>  {<br>    selector: &#39;app-root&#39;,<br>    template: `&lt;div&gt;{{title}}&lt;/div&gt;`,<br>    styles: []<br>  }<br>)<br>export class AppComponent {<br>    title = &#39;my-second-app&#39;;<br>}</pre><p>Different file, same story: decorated class. Instead of@NgModule, however, there is@Component. Components are the actual pieces being displayed on your website. The decorator attributes are:</p><ol><li>selector — This is the HTML tag which will be replaced with a component. In this case it’s app-root, which means Angular will find &lt;app-root&gt;&lt;/app-root&gt; in index.html one the directory above— yeah we just figured out what one of those files does!</li><li>templateUrl — This is the HTML template for this Component. If you did --minimal, this will be actual HTML (which I replaced with &lt;div&gt;{{title}}&lt;/div&gt;for brevity. If you didn’t, this will be a template .htmlfile.</li><li>styleUrls — Full disclosure, I am not a UI/UX person (yet?), and I despise working with CSS. But here’s where you’ll find it.</li></ol><h4>An Angular Component is just an Object</h4><p>So the HTML is in a separate file/blob, which is defined in the decorator… then what does the actual class do?</p><p>Runs our code of course! Right now it’s just one line: title = my first app. Let’s imagine for a second that Angular was written for Python. In this case (full disclosure, I’ve never used a Class decorator in Python) our code above would look like:</p><pre>from Angular.core import Component</pre><pre>@Component(<br>    selector=&quot;app-root&quot;,<br>    templateURL=&quot;&quot;&quot;&lt;div&gt;{{title}}&lt;/div&gt;&quot;&quot;&quot;,<br>    styleUrls=[]<br>)<br>class AppComponent():<br>   title=&quot;my-second-app&quot;</pre><p>A Python-Angular app would be surprisingly similar. Comparing TypeScript to Python, it becomes obvious thattitle is a just TypeScript class property ( or Python class attribute). And here’s an important note: our HTML template has access to class properties.</p><p>Take another look at the “minimal” template text and notice the {{title}} thing embedded in the HTML. It’s probably obvious that this displays the page title, and that the curly braces are responsible. But what’s going on exactly?</p><ol><li>Curly braces in Angular indicate one-way-binding from the app to the view. If AppComponent.title changes, so will {{title}}. Get used to hearing about “binding”; this simply means one thing (e.g. the angular app) causes another thing (e.g. the webpage) to change.</li><li>So why doesn’t {{title}} need this. or self. or AppComponent.in front of the property name? Because the template lives inside the class! The decorator injects this as a Class property. So in fact, the only variables the HTML can see are it’s own class properties!</li></ol><h4>Angular Components Have Class Methods</h4><p>So above was an example of one-way-binding being used to update the view from the app. The opposite one-way-bind would be the view updating the app via an event.</p><p>Let’s create a Button which invokes a class method and changes the title to “Clicked Title”:</p><pre>import { Component } from &#39;@angular/core&#39;;</pre><pre>@Component(<br>  {<br>    selector: &#39;app-root&#39;,<br>    template: `&lt;button (click) = &quot;newTitle()&quot;&gt;{{title}}&lt;/button&gt;`,<br>    styles: []<br>  }<br>)<br>export class AppComponent {<br>    title = &#39;my-second-app&#39;;</pre><pre>    newTitle() {<br>      this.title = &#39;Clicked Title&#39;;<br>      console.log(&#39;Title was changed!&#39;);<br>    }<br>}</pre><p>In our imaginary Python Angular language, this might look like:</p><pre>from Angular.core import Component</pre><pre>@Component(<br>    selector=&quot;app-root&quot;,<br>    templateURL=&quot;&quot;&quot;<br>      &lt;button (click) = &quot;newTitle()&quot;&gt;<br>        {{title}}<br>      &lt;/button&gt;&quot;&quot;&quot;,<br>    styleUrls=[]<br>)<br>class AppComponent():<br>  title=&quot;my-second-app&quot;</pre><pre>  def newTitle(self):<br>    self.title=&quot;Clicked Title&quot;<br>    print(&quot;Title was changed!&quot;)</pre><p>Great! In our HTML blob, we can access class methods! And class methods, of course, can access Class properties! Notice the () surrounding the click property. The parenthesis let Angular know that it’s looking for a Class method to make an event out of— in this case it’sAppComponent.newTitle().</p><h4>Bonus: Constructors (aka __init__())</h4><p>Often libraries and functions need to be imported into components. Take for example CookieService, which handles saving and retrieving variables as Cookies. Instead of pip install ngx-cookie-service, it’s npm install ngx-cookie-service.</p><p>If we install this library and incorporate this into our example:</p><pre>import { Component } from &#39;@angular/core&#39;;<br>import { CookieService } from &#39;ngx-cookie-service&#39;;</pre><pre>@Component(<br>  {<br>    selector: &#39;app-root&#39;,<br>    template: `&lt;div&gt;&lt;/div&gt;`,<br>    styles: []<br>  }<br>)<br>export class AppComponent {<br>    title = &#39;cookie-test&#39;;<br>    <br>    constructor( private cookieService<strong>:</strong> CookieService ) { }</pre><pre>    newTitle() {<br>      this.title = &#39;Clicked Title&#39;;<br>      console.log(&#39;Title was changed!&#39;);<br>      this.cookieService.set(&#39;title&#39;, this.title);<br>      this.title = this.cookieService.get(&#39;title&#39;);</pre><pre>    }<br>}</pre><p>In our imaginary Python Angular project, this might look like:</p><pre>from Angular.core import Component<br>from ngx_cookie_service import CookieService</pre><pre>@Component(<br>    selector=&quot;app-root&quot;,<br>    templateURL=&quot;&quot;&quot;&lt;div&gt;&lt;/div&gt;&quot;&quot;&quot;,<br>    styleUrls=[]<br>)<br>class AppComponent():<br>  title=&quot;my-second-app&quot;</pre><pre>  def __init__(self, cookieService: CookieService):<br>    self.cookieService = cookieService</pre><pre>  def newTitle(self):<br>    self.title = &quot;Clicked Title&quot;<br>    print(&quot;Title was changed!&quot;)<br>    self.cookieService.set(&#39;title&#39;, self.title)<br>    self.title = self.cookieService.get(&#39;title&#39;)</pre><p>constructor is simply __init__ in Python! In the Angular example cookieService would be a provider in app.module.ts which would be injected into AppComponent with the help of TypeScript types. In the Python example, I would have to use type hinting to indicate to our imaginary Angular back end that this should be a CookieService object.</p><p>Also, you are correct: the example above doesn’t do anything useful.</p><h4>Same But Different</h4><p>Python and Angular are obviously entirely different beasts, but all object-oriented programming is similar to some extent. In every case, you have a class, you have attributes, and you have class methods. And all Angular is is just object-oriented-programming.</p><p>If there is anything you should take away from this, just remember: An Angular Component is just a Class!</p><h4>Further Reading</h4><p>With this new mindset, why not take another look at the <a href="https://angular.io/tutorial">Tour of Heroes Angular tutorial</a>?</p><p>Also be sure to brush up on:</p><ol><li><a href="https://realpython.com/python3-object-oriented-programming/">Python Object Oriented Programming</a></li><li><a href="https://www.typescriptlang.org/docs/handbook/classes.html">Typescript Object Oriented Programming</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9eb584c98463" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/gentle-intro-to-angular-for-frustrated-python-devs-9eb584c98463">Gentle Intro to Angular for Frustrated Python Devs</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>