python

React with TypeScript: Best Practices

React and TypeScript are two awesome technologies used by a lot of developers these days. Knowing how to do things can get tricky, and sometimes it's hard to find the right answer. Not to worry. We've put together the best practices along with examples to clarify any doubts you may have. Let's dive in! How React and TypeScript Work Together Before we begin, let's revisit how React and TypeScript work together. React is a "JavaScript library for building user interfaces", while TypeScript is a "typed superset of JavaScript that compiles to plain JavaScript." By using them together, we essentially build our UIs using a typed version of JavaScript. The reason you might use them together would be to get the benefits of a statically typed language (TypeScript) for your UI. This means more safety and fewer bugs shipping to the front end. Does TypeScript Compile My React Code? A common question that’s always good to review is whether TypeScript compiles your React code..

How Do Developers See Themselves? A Quantified Look

This article was originally published by SlashData. Thank you for supporting the partners who make SitePoint possible. For the first time in our Q2 2019 Developer Economics survey, we tried to introduce developers in their own words by asking them about how they see themselves. We provided a set of 21 words and asked them to choose up to five to form a word sketch of their personality. We also gave them the opportunity to provide their own text description. Here’s what we got: Over half of the developers say they are logical Perhaps unsurprisingly, nearly six out of ten developers say they are logical. And as it turns out this is the most popular choice of description across all software development sectors, except in games development. Next in line, but some way behind, are the descriptors team player and introvert at 37% each. By comparison, just 10% label themselves as an extrovert. But can you guess which programmers consider themselves less introverted? Those involved in the A..

Learn End-to-end Testing with Puppeteer

Puppeteer is a Node library which provides a high-level API to control Chrome or Chromium over the DevTools Protocol. Puppeteer runs headless by default, but can be configured to run full (non-headless) Chrome or Chromium. In this tutorial, we’ll learn what testing is, the different types of testing, and then we’ll use Puppeteer to perform end-to-end testing on our application. By the end of this tutorial, you should be able to end-to-end test your apps easily with Puppeteer. Prerequisites For this tutorial, you need a basic knowledge of JavaScript, ES6+ and Node.js. You must also have installed the latest version of Node.js. We’ll be using yarn throughout this tutorial. If you don’t have yarn already installed, install it from here. You should also know the basics of Puppeteer. To understand the basics of Puppeteer, check out this simple tutorial. To make sure we’re on the same page, these are the versions used in this tutorial: Node 13.3.0 npm 6.13.2 yarn 1.21.1 puppeteer 2.0...

15 Top WordPress Themes to Use in 2020

This sponsored article was created by our content partner, BAW Media. Thank you for supporting the partners who make SitePoint possible. Overworked, overstressed, and flat out fed up with starting every website design from scratch? Here are some WordPress theme solutions you’ll appreciate. Maybe you need to switch to an easy-to-use theme — a WordPress theme that’s crazy-fast and gives you reliable performance may be your cup of tea. Tired of having to build your websites from scratch? It’s totally unnecessary unless for some reason you absolutely want to. Before you blame yourself for the situation you find yourself in, consider this: maybe it’s the tools you’re using. You may be trying to build a house without the use of power tools, scaffolding, or helpful aids. One of the following 15 top WordPress themes should prove to be the solution to your problem. In fact, more than one of them could probably serve quite nicely. Grab a cup of coffee and let’s get started. 1. BeTheme: Re..

Quick Tip: Get URL Parameters with JavaScript

URL parameters (also called query string parameters or URL variables) are used to send small amounts of data from page to page, or from client to server via a URL. They can contain all kinds of useful information, such as search queries, link referrals, product information, user preferences, and more. In this article, we’ll show you how to parse and manipulate URL parameters using JavaScript. Getting a URL Parameter In modern browsers, this has become a lot easier, thanks to the URLSearchParams interface. This defines a host of utility methods to work with the query string of a URL. Assuming that our URL is https://example.com/?product=shirt&color=blue&newuser&size=m, we can grab the query string using window.location.search: const queryString = window.location.search; console.log(queryString); // ?product=shirt&color=blue&newuser&size=m We can then parse the query string's parameters using URLSearchParams: const urlParams = new URLSearchParams(queryString); Then we call an..

How Four Programmers Got Their First Python Jobs

No one really knows how to do a job before they do it. Most people land a coveted position through a strange alchemy of related experience, networking, and hard work. The real experience is the job itself. That’s when you get the opportunity to apply what you know to real-world problems and see it pay off. The following four programmers earned their first Python jobs in different ways. Some had prior Python experience, some didn’t. Some knew what they were getting into, others found out later. Understanding how they landed their first Python job might help you land yours. Here’s how they did it. Nathan Grieve First Python job: Data Scientist How Nathan Got the Job While completing my Physics degree, I applied for a data science job with a small tech startup that primarily used Python (and SQL). The thing is, I didn’t have experience with Python at the time. When the interview came around, I answered the programming questions by using pseudocode to demonstrate I understood the concep..

4 Reasons to Use Image Processing to Optimize Website Media

This sponsored article was created by our content partner, BAW Media. Thank you for supporting the partners who make SitePoint possible. Image optimization is a big deal when it comes to website performance. You might be wondering if you’re covering all the bases by simply keeping file size in check. In fact, there’s a lot to consider if you truly want to optimize your site’s images. Fortunately, there are image processing tools and content delivery networks (CDNs) available that can handle all the complexities of image optimization. Ultimately, these services can save you time and resources, while also covering more than one aspect of optimization. In this article, we’ll take a look at the impact image optimization can have on site performance. We’ll also go over some standard approaches to the problem, and explore some more advanced image processing options. Let’s get started! Why Skimping on Image Optimization Can Be a Performance Killer If you decide not to optimize your images..

JavaScript’s New Private Class Fields, and How to Use Them

ES6 introduced classes to JavaScript, but they can be too simplistic for complex applications. Class fields (also referred to as class properties) aim to deliver simpler constructors with private and static members. The proposal is currently a TC39 stage 3: candidate and is likely to be added to ES2019 (ES10). Private fields are currently supported in Node.js 12, Chrome 74, and Babel. A quick recap of ES6 classes is useful before we look at how class fields are implemented. ES6 Class Basics JavaScript's object-oriented inheritance model can confuse developers coming from languages such as C++, C#, Java, and PHP. For this reason, ES6 introduced classes. They are primarily syntactical sugar but offer more familiar object-oriented programming concepts. A class is an object template which defines how objects of that type behave. The following Animal class defines generic animals (classes are normally denoted with an initial capital to distinguish them from objects and other types):..

The Top 10 SitePoint Guides & Tutorials of 2019

In 2019, we published hundreds of new guides, tutorials, and articles. Whether we showed you how to use new technologies and tools, or published career advice from people at the top of their game, our aim was always to help you level up as a web developer. Though tech moves fast, all of those articles are still relevant now in the start of 2020. To celebrate a year concluded, we wanted to take a look at the 10 pieces our readers enjoyed and shared the most in 2019. Hopefully, there's something here that's useful to you going into this new year. What Is Functional Programming? As a programmer, you probably want to write elegant, maintainable, scalable, predictable code. The principles of functional programming, or FP, can significantly aid in these goals. Ali Spittel walks you through these principles, using JavaScript to demonstrate them. ➤ Read What Is Functional Programming? 10 Must-have VS Code Extensions for JavaScript Developers Visual Studio Code is undoubtedly the..

How to Apply CSS3 Transforms to Background Images

CSS transformations are great, but they don't (yet?) apply to background images. This article presents a workaround for those times when you really do want to rotate a background image, or to keep a background image fixed while its container element is rotated. This article was updated in 2020. Scaling, skewing, and rotating any element is possible with the CSS3 transform property. It's supported in all modern browsers without vendor prefixes. #myelement { transform: rotate(30deg); } Great stuff. However, this rotates the whole element — its content, border and background image. What if you only want to rotate the background image? Or what if you want the background to remain fixed while the content is rotated? There’s no W3C CSS proposal for background-image transformations. It would be incredibly useful, so perhaps one will appear eventually, but that doesn't help developers who want to use similar effects today. One option would be to create a new background im..