Posted on Leave a comment

Writing, Running, Debugging, and Testing Code In PyCharm

How To Write Python Code In Pycharm?

Every code or file within Pycharm is written inside a project. This means, everything in PyCharm is written with respect to a Project and the first thing that you need to create before you can write any code is a project. So, let’s see how we can create a project in PyCharm.

➮ After successfully installing PyCharm, the welcome screen comes up. Click Create New Project.

The Create New Project window opens up.

✶ In this window specify the location of the project where you want to save the files.

✶ Expand the Python Interpreter menu. Here, you can specify whether you want to create a new project interpreter or reuse an existing one. From the drop-down list, you can select one of the options: Virtualenv, Pipenv, or Conda. These are the tools that help us to keep dependencies required by different projects and are separated by creating isolated Python environments for each of them. You can also specify the location of the New environment and select a Base interpreter (for example Python2.x or Python3.x) from the options available. Then we have checkboxes to select Inherit global site-packages and Make available to all projects. Usually, it is a good idea to keep the defaults.

✶ Click Create on the bottom right corner of the dialog box to create the new project.

Note: You might be notified that: Projects can either be opened in a new window or you can replace the project in the existing window or be attached to the already opened projects. How would you like to open the project? Select the desired option.

You might also get a small Tip of the Day popup where PyCharm gives you one trick to learn at each startup. Feel free to close this popup.

Now, we are all set to start writing our first Python code in PyCharm.

  • Click on File.
  • Choose New.
  • Choose Python File and provide a name for the new file. In our case we name it add. Press enter on your keyboard and your new file will be ready and you can write your code in it.

Let us write a simple code that adds two numbers and prints the result of the addition as output.

How To Run The Python Code In PyCharm?

Once the code is written, it is time to run the code. There are three ways of running the Python code in PyCharm.

Method 1: Using Shortcuts

  • Use the shortcut Ctrl+Shift+R on Mac to run the code.
  • Use the shortcut Ctrl+Shift+F10 on Windows or Linux to run the code.

Method 2: Right click the code window and click on Run ‘add’

Method 3: Choose ‘add’  and click on the little green arrow at the top right corner of the screen as shown in the diagram below.

How To Debug The Code Using Breakpoints?

While coding, you are bound to come across bugs especially if you are working with a tedious production code. PyCharm provides an effective way of debugging your code and allows you to debug your code line by line and identify exceptions or errors with ease. Let us have a look at the following example to visualize how to debug your code in PyCharm.

Example:

Output:

Note: This is a very basic example and has been just used for the purpose to guide you through the process of debugging in PyCharm. The example computes the average of two numbers but yields different results in the two print statements. A spoiler: we have not used the brackets properly which results in the wrong result in the first case. Now, we will have a look at how we can identify the same by debugging our Python code in PyCharm.

Debugging our code:

Step 1: Setting The Breakpoint

The first requirement to start debugging our code is to place a breakpoint by clicking on the blank space to the left of line number 1 ( this might vary according to your code and requirements). This is the point where the program will be suspended and the process of debugging can be started from here, one line at a time.

Step 2: Start Debugging

Once the breakpoint is set the next step is to start debugging using one of the following ways:

  • Using Shortcuts: Ctrl+Shift+D on Mac or Shift+Alt+F9 on Windows or Linux.
  • Right-click on the code and choose Debug ‘add’.
  • Choose ‘add’  and click on the icon on the top right corner of the menu bar.

Once you use any one of the above methods to start debugging your code, the Debug Window will open up at the bottom as shown in the figure below. Also, note that the current line is highlighted in blue.

Step 3: Debug line by line and identify the error (logical in our case). Press F8 on your keyboard to execute the current line and step over to the next line. To step into the function in the current line, press F7. As each statement is executed, the changes in the variables are automatically reflected in the Debugger window.

How To Test Code In PyCharm?

For any application or code to be operational, it must undergo unit test and PyCharm facilitates us with numerous testing frameworks for testing our code. The default test runner in Python is unittest, however, PyCharm also supports other testing frameworks such as pytestnosedoctesttox, and trial.

Let us create a file with the name currency.py and then test our file using unit testing.

Now, let us begin unit testing. Follow the steps given below:

Step 1: Create The Test File

To begin testing keep the currency.py file open and execute any one of the following steps:

  1. Use Shortcut: Press Shift+Cmd+T on Mac or Ctrl+Shift+T on Windows or Linux.
  2. Right-click on the class and select Go To ➠ Test. Make sure you right-click on the name of the class to avoid confusion!
  3. Go to the main menu ➠ select Navigate ➠ Select Test

Step 2: Select Create New Test and that opens up the Create Test window. Keep the defaults and select all the methods and click on OK.

✶ PyCharm will automatically create a file with the name test_currency.py with the following tests within it.

Step 3: Create the Test Cases

Once our test file is created we need to import the currency class within it and define the test cases as follows:

Step 4: Run the Unit Test

Now, we need to run the test using one of the following methods:

  • Using Shortcut: Press Ctrl+R on Mac or Shift+F10 on Windows or Linux.
  • Right-click and choose Run ‘Unittests for test_currency.py’.
  • Click on the green arrow to the left of the test class name and choose Run ‘Unittests for test_currency.py’.

You will since that two tests are successful while one test fails. To be more specific unit test for test_euro() and test_yen() are successful while the test fails for test_pound().

Output:

That brings us to the end of this section and it is time for us to move on to a very important section of our tutorial where we will be discussing numerous tips and tricks to navigate PyCharm with the help of some interesting shortcuts. We will also discuss in brief about some of the tools like Django that we can integrate with PyCharm. So, without further delay lets dive into to next section.

Please click on the Next link/button given below to move on to the next phase of PyCharm journey!






The post Writing, Running, Debugging, and Testing Code In PyCharm first appeared on Finxter.

Posted on Leave a comment

Freelance Software Development in the United States (US)

USA

The next disruption is about to happen in the freelancing space. Freelancing platforms such as Upwork and Fiverr grow double-digit per year.

But what if you’re living in the US? Is freelancing still a great opportunity for you—given the worldwide competition? How much can you earn in the US?

In this article, we’re going to answer these most common questions!

What’s the Hourly Rate of an US-Based Freelance Developer?

What’s the hourly rate of a freelance developer? If you’re like me, you want to peek into the potential of a given profession before you commit years of your life to any profession like freelance developing.

The average freelance developer in the US earns $56 per hour with conservative estimates ranging as low as $31 and aggressive estimates ranging as high as $82.

The following table compares the hourly rates of employed developers and freelance developers:

Job Description Status Hourly Rate
Web Developer Employee $31.62
Freelancer $34.78
PHP Developer Employee $46.28
Freelance $50.90
.Net Developer Employee $55.06
Freelance $60.56
Python Developer Employee $56.90
Freelance $62.59

About the Data. Our data is based on various online sources such as indeed.com, neuvoo.co.uk, and other portals where professionals can report their earnings. We state the sources below in the image captions.

We modified the expected earnings of a freelancer by increasing the average earnings of an employed professional by 10%. This is based on the findings of this study: the average freelancer earns about 10% more than his employed counterpart. We found that in practice, the difference is often much higher than that—freelancers earning much more than employees. One of the reasons may be that freelancers have more control of their earnings—an ambitious freelancer tends to earn a higher percentage more than an ambitious employee in the same profession. This is because there are no caps in freelance earnings.

If you want to earn your full-time income working in your part-time freelancing business, check out our course “Become a Python Freelance Developer”.


The average hourly rate of an employed web developer is $31.62 per hour in the US. The average hourly rate of a freelance web developer is $34.78 in the US.

The average hourly rate of an employed Python developer is $56.90 per hour in the US. The average hourly rate of a freelance Python developer is $62.59 in the US.

The average hourly rate of an employed PHP developer is $46.28 per hour in the US. The average hourly rate of a freelance PHP developer is $50.90 in the US.

The average hourly rate of an employed .Net developer is $55.06 per hour in the US. The average hourly rate of a freelance .Net developer is $60.56 in the US.

Related Article: Freelance Developer Hourly Rate By Regions and Professions

How Do You Compete with Cheap Labor Countries as an US-based Freelance Developer?

In the following video, I discuss little-known but very effective strategies to compete in a globalized economy as a US-based freelance developer.

How Many Freelance Software Developers Are There in the United States?

How many freelance developers are there in the US? There’s no official and precise answer. However, based on three credible sources—Upwork, Freelancer Union, McKinsey—I calculated an estimation stemming from each source.

Here are our estimations for the number of freelancers based on three independent data sources:

  • Upwork Data: 12,500,000 freelance developers in the IT sector.
  • Freelancer Union Data: 1,740,000 freelance developers in the IT sector.
  • McKinsey Data: 5,400,000 freelance developers in the IT sector.

The median of these three data points—Upwork, Freelancer Union, McKinsey—is 5,400,000 freelance developers working in an IT related field and the average is 6,560,000 freelance developers. Thus, the number of freelance developers is between 5 and 7 million.

A more in-depth explanation of these estimations is given in my detailed blog article.

Related Article: How Many Freelance Developers Are There in the US?

Where to Go From Here?

Enough theory, let’s get some practice!

To become successful in coding, you need to get out there and solve real problems for real people. That’s how you can become a six-figure earner easily. And that’s how you polish the skills you really need in practice. After all, what’s the use of learning theory that nobody ever needs?

Practice projects is how you sharpen your saw in coding!

Do you want to become a code master by focusing on practical code projects that actually earn you money and solve problems for people?

Then become a Python freelance developer! It’s the best way of approaching the task of improving your Python skills—even if you are a complete beginner.

Join my free webinar “How to Build Your High-Income Skill Python” and watch how I grew my coding business online and how you can, too—from the comfort of your own home.

Join the free webinar now!

The post Freelance Software Development in the United States (US) first appeared on Finxter.

Posted on Leave a comment

How Many Freelance Developers Are There in the US?

How many freelance developers are there in the US? There’s no official and precise answer. However, based on three credible sources—Upwork, Freelancer Union, McKinsey—I calculated an estimation stemming from each source.

Here are our estimations for the number of freelancers based on three independent data sources:

  • Upwork Data: 12,500,000 freelance developers in the IT sector.
  • Freelancer Union Data: 1,740,000 freelance developers in the IT sector.
  • McKinsey Data: 5,400,000 freelance developers in the IT sector.

The median of these three data points—Upwork, Freelancer Union, McKinsey—is 5,400,000 freelance developers working in an IT related field and the average is 6,560,000 freelance developers. Thus, the number of freelance developers is between 5 and 7 million.

Methodology

To come up with an exact answer on how many freelance developers there are in the US, I decided to use several independent data sources and aggregate the results. Here are the different sources used to estimate the number of freelancers in the United States.

  • Upwork: Upwork is the largest freelancing marketplace in the world.
  • Freelancer Union Report: “Freelancers Union is a non-profit organization in the United States of America. The organization provides advocacy, programming and curated insurance benefits for freelancers through partnerships.” (source)
  • McKinsey Report “Independent Work”: McKinsey funded a large-scale report about the state of the independent work sector.

Results

Upwork

  • Upwork has 18,000,000 registered freelancers in 2020. (source)
  • About 30% of the revenue is generated by US-based freelancers. (source)
  • Based on these data points, there are approximately 18,000,000 * 30% = 5,000,000 Upwork freelancers in the US.
  • There are 12 categories on Upwork—three of which are “freelance developing”: (1) IT&Networking, (2) Data Science & Analytics, (3) Web, Mobile, & Software Development.
  • Assuming an approximately equal distribution of freelancers in broad categories, the percentage of freelance developers is 3/12 = 25%.
  • Based on this, the total number of freelancers in the US on Upwork is 25% * 5,000,000 = 1,250,000.
  • The total market of freelancing is $1 trillion USD in 2020. (source)
  • Gross services volume (GSV) increased by 28% year-over-year to $1.76 billion for the full year. (source)
  • Upwork represents only a small fraction of the marketplace (although many freelance developers will have an account).
  • Assuming only 10% of all freelance developers use Upwork, the total number of freelancers in the US can be estimated as 12,500,000.

Freelancer Union Report

  • There are 58,000,000 freelancers in the US. (source)
  • 3% of all workers, freelancers or employees, are in the IT sector. (source)
  • Based on these two data points, there are at least 58,000,000 * 3% = 1,740,000 freelancers. This is very conservative estimation because the IT sector will be larger within the freelancer space than outside it.

McKinsey Report “Independent Work”

  • There are 54,000,000 million freelancers in the US. (source)
  • Approximately 10% of the income earned is done by computer and technology professions. (source)
  • As a result, there are 5,400,000 freelance developers in the US.

Summary

Here are our estimations for the number of freelancers based on three independent data sources:

  • Upwork Data: 12,500,000 freelance developers in the IT sector.
  • Freelancer Union Data: 1,740,000 freelance developers in the IT sector.
  • McKinsey Data: 5,400,000 freelance developers in the IT sector.

The median of these three data points is 5,400,000 freelance developers working in an IT related field.

The average of these three data points is 6,560,000 freelance developers working in an IT related field.

Do you want to become one of them? As it turns out, freelance developing is a profitable niche where average workers earn six figures and beyond! Check out the following resources:

Where to Go From Here?

Enough theory, let’s get some practice!

To become successful in coding, you need to get out there and solve real problems for real people. That’s how you can become a six-figure earner easily. And that’s how you polish the skills you really need in practice. After all, what’s the use of learning theory that nobody ever needs?

Practice projects is how you sharpen your saw in coding!

Do you want to become a code master by focusing on practical code projects that actually earn you money and solve problems for people?

Then become a Python freelance developer! It’s the best way of approaching the task of improving your Python skills—even if you are a complete beginner.

Join my free webinar “How to Build Your High-Income Skill Python” and watch how I grew my coding business online and how you can, too—from the comfort of your own home.

Join the free webinar now!

The post How Many Freelance Developers Are There in the US? first appeared on Finxter.

Posted on Leave a comment

Unified Blazor UI in the Mobile Blazor Bindings Preview 5

Eilon Lipton

Eilon

I’m excited to announce that today we are releasing the Mobile Blazor Bindings Preview 5 update that adds support for sharing UI between web apps and mobile/desktop apps. You can now use a Razor Class Library (RCL) to build your UI and app logic once and use it in a Blazor Web app and in a Mobile Blazor Bindings app. This release also includes many other improvements, such as support for Shell with Blazor @page routing, SkiaSharp for rich graphics, gesture recognizers, and a whole lot more!

You can build one UI using Blazor Web and host it in a Blazor Server or Blazor Web Assembly app and also in a Mobile Blazor Bindings hybrid app to target Android, iOS, macOS, and Windows:

Image cat tracker options

These are the major new features in the 0.5 Preview 5 release:

  • Build your UI in a Razor Class Library (RCL) and share the same UI between web app and native app, including static assets such as CSS and images (community contribution from Jan-Willem Spuij)
  • Support for Shell with Routing, including the Razor @page directive (community contribution from Lachlan Gordon
  • Support for SkiaSharp graphics (community contribution from Lachlan Gordon
  • Gesture recognizers (tap, swipe, etc.)
  • Dual-screen device support
  • Added FontImageSource, DatePicker, TimePicker
  • Simplified Grid layout syntax
  • Update to Xamarin.Forms 4.8
  • Nightly package feed
  • OSS docs on GitHub
  • And several bug fixes and other small improvements
  • The full list of closed issues is here: https://github.com/xamarin/MobileBlazorBindings/milestone/5?closed=1

Get started

To get started building a Blazor Hybrid app with Experimental Mobile Blazor Bindings preview 5, install the .NET Core 3.1 SDK, have Visual Studio with the Mobile development with .NET (Xamarin.Forms) and ASP.NET and web development workloads installed, and then run the following command:

dotnet new -i Microsoft.MobileBlazorBindings.Templates::0.5.50-preview

And then create your first project by running this command:

dotnet new blazorhybrid -o MyHybridApp

Note: For additional information on required software, please check the Getting Started article.

Now open it in Visual Studio and run it on Android, iOS, Windows, or macOS. That’s it! You can find additional docs and tutorials on https://docs.microsoft.com/mobile-blazor-bindings/. We have a new tutorial for building a Razor Class Library and including it in a Blazor Server app as well as targeting Android, iOS, macOS, and Windows platforms.

Upgrade an existing project

To update an existing Mobile Blazor Bindings project please refer to the Migrate Mobile Blazor Bindings From Preview 4 to Preview 5 topic for full details.

Razor Class Library support

Razor Class Libraries are a feature of Razor that enable you to package part of your application’s UI and logic into a reusable library. This library can then be reused in multiple web applications. Now in Mobile Blazor Bindings you can use the same library in a Blazor Hybrid application as part of a mobile or desktop app. The web content is hosted in a Web View, just like any hybrid app content, and it can interact with any native parts of the application, and the reverse is true as well. Previous versions included limited support for RCLs, and this version adds improved support for them, particularly support for serving static assets such as CSS and images, as well as support for JSInterop for interop between JavaScript and .NET code.

Shell navigation

To build a great native experience for your app you can use the Shell control that comes from Xamarin.Forms. Starting with Preview 5 you can author native Blazor pages with the @page "/search/{query}" syntax and integrate them with the Shell’s navigation (such as the Back button) and navigate to them using the new NavigationManager.NavigateToAsync($"/search/{query}") API. Pages can use the navigation manager by injecting it from the DI container as in @inject ShellNavigationManager NavigationManager.

SkiaSharp graphics

SkiaSharp is a popular cross-platform graphics library based on Google’s Skia graphics library. In Preview 5 you can directly use SkiaSharp’s Canvas APIs to render rich high-performance graphics directly in your Mobile Blazor Bindings app.

Here’s what a simple canvas might look like:

<ContentView> <StackLayout Padding="20"> <SKCanvasView OnPaintSurface="PaintSurface"/> </StackLayout>
</ContentView> @code
{ void PaintSurface(SKPaintSurfaceEventArgs e) { var canvas = e.Surface.Canvas; canvas.Clear(SKColors.Green); var paint = new SKPaint { Color = SKColors.SkyBlue, }; canvas.DrawLine(0, 0, 200, 200, paint); }
}

And here’s what a more complex canvas might render as:

SkiaSharp rendering a graph in Mobile Blazor Bindings on iOS

More information

Thank you to contributors

This release had several major contributions from community contributors:

  • Jan-Willem Spuij added support for Razor Class Libraries with static assets. He stayed up late (his time) on calls with me several times and I appreciate his hard work!
  • Lachlan Gordon added support for Shell navigation and SkiaSharp. His patience in playing time-zone ping-pong (Australia vs. USA) is most appreciated and resulted in high quality contributions!

Thanks you to Jan-Willem, Lachlan, and everyone else who contributed to this release!

What’s next? Let us know what you want!

This project relies on your feedback to help shape the future of Blazor for native and hybrid scenarios. Please share your thoughts on this blog post or at the GitHub repo so we can keep the discussion going.

Posted on Leave a comment

Freelance Developers Specialize! But Where?

As a freelance developer, many routes lead to success. But this doesn’t mean that you shouldn’t decide which route to take and stick to it!

Quite contrarily, the worst is to be a jack-of-all-trades—a freelance developer who doesn’t have the guts to focus on one specialized skill set. Specialization is critical for your success as a freelance developer. Specialists earn more money, learn faster because they can build on knowledge they’ve already acquired, are more efficient because they don’t need to spend hours and hours learning about a new field for each gig they take, and enjoy a higher status as they’re perceived as “experts in their fields”.

In the following, you’re going to learn about the most popular niches in the freelance developing space.

Freelance Web Developer

The most popular freelance developer specialization is web developing. This makes sense because most freelancing gigs are brokered over the web. So, why not sell your skills creating websites and solving other types of problems in the web.

As a freelance web developer, you must discuss requirements with clients, propose website ideas, design web pages, fix broken databases, work with CMS, write HTML code, add JavaScript widgets, and collaborate with designers. You can focus on front-end, or back-end, or full-stack web development.

  • Front-end web development: Create websites but focus on user interfaces, usability, and design. You use front-end technologies such as JavaScript, HTML, CSS and Bootstrap.
  • Back-end web development: Create web application but focus on server-side logic—databases, scaling the application to hundreds of thousands of users, distributed systems.
  • Full-stack web development: Create web applications but be able to do both front-end and back-end web development. These highly skilled professionals are sought by many small companies that cannot afford to hire multiple web developers. Also, it helps you understand the big picture of a web application which is a vital skill for leaders and higher management.

Freelance Full Stack Developer

“A full stack web developer is a person who can develop both client and server software. In addition to mastering HTML and CSS, he/she also knows how to: Program a browser (like using JavaScript, jQuery, Angular, or Vue) Program a server (like using PHP, ASP, Python, or Node)” (source)

Freelance Frontend Developer

“A front-end web developer is responsible for implementing visual elements that users see and interact with in a web application. They are usually supported by back-end web developers, who are responsible for server-side application logic and integration of the work front-end developers do.” (source)

Freelance Backend Developer

“Back-end developers work hand-in-hand with front-end developers by providing the outward facing web application elements server-side logic. In other words, back-end developers create the logic to make the web app function properly, and they accomplish this through the use of server-side scripting languages like Ruby or.” (source)

Freelance Qt Developer

“Qt (pronounced “cute”) is a free and open-source widget toolkit for creating graphical user interfaces as well as cross-platform applications that run on various software and hardware platforms such as Linux, Windows, macOS, Android or embedded systems with little or no change in the underlying codebase while still being a native application with native capabilities and speed (source).”

As a freelance Qt developer, you create application that use Qt as a GUI framework. Qt is a widely distributed framework that is used for many Linux systems, Adobe, Google Earth, Photoshop, and many popular applications. Because of the wide distribution of the Qt framework—and the high barrier to entry—freelancing as a Qt developer can be very profitable. However, the learning curve is quite steep as well and you must be willing to read many books and spend hundreds of hours learning this exciting framework.

Freelance Quant Developer

Quants are finance geeks that use quantitative analysis to gain insight into financial data. Quants have a thorough statistical education because they must understand the statistical significance of their insights. The financial niche pays above average and you can work for large financial firms that crunch numbers to come to predictions regarding undervalued stocks or financial instruments.

The potential to work as a freelancer is relatively limited because most large financial institutions rely on quant employees. However, more and more financial startups (FinTechs) hire quant developers to create trading bots and automize financial analysis. Those startups often prefer to hire freelance quant developers.

Should you become a freelance quant developer? In my opinion, this is a financially very attractive opportunity paying much more than six-figures—but only if you’re very interested in finance and you have a knack for maths, data science, and statistics.

Freelance Software Developer

A freelance software developer is a person who professionally creates software through computer programming by selling his services to companies, organizations, or individuals in an independent contractor relationship. There are a multitude of programming languages and frameworks designed to create software—so, the niche description is still very broad and general. You must choose your specific niche in more detail. However, the term “freelance software developer” is mostly used for larger-scale software projects where the freelancer is hired on a per-project basis.

Freelance Java Developer

“Java is a class-based, object-oriented programming language that is designed to have as few implementation dependencies as possible. It is a general-purpose programming language intended to let application developers write once, run anywhere (WORA), meaning that compiled Java code can run on all platforms that support Java without the need for recompilation.” (source)

Freelance Developer Embedded

“An embedded system is a computer system—a combination of a computer processor, computer memory, and input/output peripheral devices—that has a dedicated function within a larger mechanical or electrical system. It is embedded as part of a complete device often including electrical or electronic hardware and mechanical parts. Because an embedded system typically controls physical operations of the machine that it is embedded within, it often has real-time computing constraints. Embedded systems control many devices in common use today. Ninety-eight percent of all microprocessors manufactured are used in embedded systems.” (source)

Freelance eLearning Developer

“A Learning Engineer is someone who draws from evidence-based information about human development — including learning — and seeks to apply these results at scale, within contexts, to create affordable, reliable, data-rich learning environments.” (source)

Freelance Email Developer

“The Email Developer is responsible for design and execution of responsive design and development of email promotions ensuring that projects are completed.” (source)

Freelance eCommerce Developer

“The eCommerce developers are normally web developers with additional skills for the tools and platforms commonly used in eCommerce businesses. The main skills of an eCommerce developer should include: HTML, CSS, XML. JavaScript, Node.” (source)

Freelance ETL Developer

“An ETL Developer is an IT specialist who designs data storage systems for companies, and works to fill that system with the data that needs to be stored. ETL Developers generally work as part of a team. They are sometimes employed by a single company.” (source)

Freelance React Developer

“In a nutshell, a React developer designs and implements user-facing features for websites and applications using React.js. They are known as front-end developers, a sub-group of developers that manage everything that users see on their web browsers or applications.” (source)

Freelance Developer WordPress

“WordPress Developers are responsible for both back-end and front-end development, including creating WordPress themes and plugins. They have different programming skills such as namely PHP, HTML5, CSS3, and JavaScript.” (source)

Freelance Tableau Developer

“A Tableau developer creates computer system and data visualization solutions to improve business processes. This job involves tasks such as creating Tableau dashboard reports, working with developers, creating business intelligence reports and visualizations, and attending feedback sessions to improve systems.” (source)

Freelance Tally Developer

A Tally Developer uses a comprehensive development suite to develop, and deploy solutions for Tally. “Tally is a windows-based Enterprise Resource Planning software. The software handles Accounting, Inventory Management, Order Management, Tax Management, Payroll, Banking and many such requirements of the business. It supports all day-to-day processes from recording invoices to generating various MIS reports.” (source)

Freelance Zoho Developer

As a Zoho Developer, you create apps on the Zoho Developer platform that “is a free cloud platform for developers to create ready-to-deploy cloud applications on top of the Zoho platform. Unlike conventional cloud platforms, the Zoho Developer Console lets you quickly build enterprise level applications through drag and drop tools.” (source)

Freelance Unity Developer

“A unity developer creates apps for the unity platform. “Unity is a cross-platform game engine developed by Unity Technologies, first announced and released in June 2005 at Apple Inc.’s Worldwide Developers Conference as a Mac OS X-exclusive game engine. As of 2018, the engine had been extended to support more than 25 platforms.” (source)

Freelance UI Developer

A UI developer creates user interfaces to interact with the user of a given application. “Marketable programming skills for UI developers include HTML, CSS, JavaScript, AJAX, JSON, jQuery, Java, Ruby on Rails, and SQL database development. UI devs will also benefit from learning Photoshop, Flash, Flex and Illustrator from the Adobe Creative Suite.” (source)

Freelance Unreal Developer

An Unreal Developer creates apps for the Unreal engine. “Unreal Engine is the world’s most open and advanced real-time 3D creation platform for photoreal visuals and immersive experiences.” (source)

Freelance Umbraco Developer

An Umraco Developer works with the Umbraco platform, maintains it, and extends it with new features. “Umbraco is an open-source content management system (CMS) platform for publishing content on the World Wide Web and intranets. It is written in C# and deployed on Microsoft based infrastructure. Since version 4.5, the whole system has been available under an MIT License.” (source)

Freelance Flutter Developer

A Flutter Developer creates apps for the Flutter platform. “Flutter is Google’s UI toolkit for building beautiful, natively compiled applications for mobile, web, and desktop from a single codebase.” (source)

Freelance Filemaker Developer

“The primary qualifications for a FileMaker developer include experience with FileMaker database solutions, knowledge of database administration, and skills in related programming languages such as SQL, Java, and Perl.” (source)

Freelance Firmware Developer

“Firmware engineers develop the software that manages electronic devices. These positions require proficiency in programming languages and applications, as well as good communications skills.” (source)

Freelance Flask Developer

A Flask Developer is a programmer who develops apps in Python’s Flask framework. “Flask is a micro web framework written in Python. It is classified as a microframework because it does not require particular tools or libraries. It has no database abstraction layer, form validation, or any other components where pre-existing third-party libraries provide common functions. However, Flask supports extensions that can add application features as if they were implemented in Flask itself. Extensions exist for object-relational mappers, form validation, upload handling, various open authentication technologies and several common framework related tools.” (source)

Freelance Django Developer

A Django developer creates, maintains, and improves apps written in Python’s Django framework. “Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. It’s free and open source.” (source)

Freelance Game Developer

“Game developers are people like you with math, computer, or creative arts skills. They spend their time programming and developing games. This includes programming console, computer, and mobile video games. They are persistent, they are a little bit lucky, and they manage to get hired to do develop video games.” (source)

Freelance Go Developer

A Go Developer is a programmer who uses the Golang programming language to create, maintain, and improve Go applictions. “Go is a really flexible language, able to solve a lot of problems. You can use it for system and network programming, big data, machine learning, audio and video editing, and more.” (source)

Freelance GIS Developer

“The job of a geographic information systems developer is to design and execute applications used to support GIS data; “GIS” refers simply to applications and software which collect data from specific locations. The applications developed by those in this position are also used to edit and analyze data and create maps.” (source)

Freelance Hubspot Developer

A Hubspot developer is involved in managing access to the HubAPI. “This domain is owned by Hubspot. The company provides a range of online marketing and sales technology and services. The main purpose of cookies set by this host is: Targeting/Advertising.” (source)

Freelance HTML Developer

“HTML developers are responsible for the complete end-to-end coding of websites. They provide technical support to website users, direct HTML projects, code sites, develop web-based applications, and perform testing on Web sites and their background code.” (source)

Freelance LabVIEW Developer

A Labview developer has passed the LabVIEW exam. “The Certified LabVIEW Developer (CLD) exam verifies the user’s ability to design and develop functional programs while minimizing development time and ensuring maintainability through proper documentation and style. Certified Developers can provide technical leadership to less experienced engineers, helping ensure their team is following best practices and becoming more competent and efficient LabVIEW programmers.” (source)

Freelance VR Developer

A VR developer specializes in virtual reality. In particular, the VR developer is involved in “development of VR and AR applications (UE4, Unity, C++, C#), development and implementation of prototypes and new functions, agile development planning, and running tests and code reviews.” (source)

Freelance VBA Developer

“A VBA Developer works with the Excel application and adapts it to the specific needs of a challenge or requirements to automate repetitive tasks and accelerate the workflow of a business. This is done using the Visual Basic for Applications and Macros – hence the term VBA developer.” (source)

Freelance UI Developer

“A UI developer’s role is to translate creative software design concepts and ideas into reality using front end technology. They understand the user interface design solution both in its practical intent and creative vision, and convert it into engineered softwares.” (source)

Freelance Blockchain Developer

“A developer responsible for developing and optimizing blockchain protocols, crafting the architecture of blockchain systems, developing smart contracts and web apps using blockchain technology are commonly called blockchain developers.” (source)

Freelance .Net Developer

“A .NET Software Developer is a software developer who specialises in building software for Microsoft’s Windows platform. They work with programming languages compatible with Microsoft’s .NET framework, including VB.NET, C# (C sharp) and F# (F sharp).” (source)

Freelance Mobile Developer

“Mobile developers are a type of software developer. They specialise in mobile technology such as building apps for Google’s Android, Apple’s iOS and Microsoft’s Windows Phone platforms. For this reason job titles for this type of role also include Android developer and iOS developer.” (source)

Freelance Magento Developer

“Magento developers are in charge of developing, maintaining, and improving their clients’ eCommerce websites. … Magento developers are in charge of developing, maintaining, and improving their clients’ eCommerce websites. Their responsibility is huge, as most of the time, Magento websites generate a lot of revenue.” (source)

Freelance iOS Developer

“An iOS developer is responsible for developing applications for mobile devices powered by Apple’s iOS operating system. Ideally, a good iOS developer is proficient with one of the two programming languages for this platform: Objective-C or Swift.” (source)

Freelance IONIC Developer

An IONIC developer creates apps for the IONIC platform. “Ionic provides tools and services for developing hybrid mobile, desktop, and Progressive Web Apps based on modern web development technologies and practices, using Web technologies like CSS, HTML5, and Sass. In particular, mobile apps can be built with these Web technologies and then distributed through native app stores to be installed on devices by utilizing Cordova or Capacitor.” (source)

Freelance Odoo Developer

An Odoo developer is involved in Odoo development. “Odoo is a suite of business management software tools including CRM, e-commerce, billing, accounting, manufacturing, warehouse, project management, and inventory management to name a few.” (source)

Freelance Outsystems Developer

An Outsystems Developer creates and ships scalable, responsive software developed with OutSystems. The rapidly developed apps integrate well with existing systems and possess high scalability.

Freelance App Developer

“An app developer is a computer software engineer whose primary responsibilities include creating, testing and programming apps for computers, mobile phones, and tablets. These developers typically work in teams, and think of ideas and concepts either for the general public, or for a specific customer need.” (source)

Freelance Android Developer

An Android developer creates mobile applications for the Android operating system. “You can make a very competitive income, and build a very satisfying career as an Android developer. Android is still the most used mobile operating system in the world, and the demand for skilled Android developers remains very high.” (source)

Freelance Angular Developer

An Angular developer is involved in the following activities: “Designing and developing user interfaces using AngularJS best practices. Adapting interface for modern internet applications using the latest front-end technologies. Writing JavaScript, CSS, and HTML. … Ensuring high performance of applications and providing support.” (source)

Freelance Database Developer

“Database developers ensure that database management systems (DBMS) can handle massive quantities of data. Also called database programmers, developers usually work as part of a software development team. … Modifying and editing databases. Designing and developing new databases.” (source)

Freelance Drupal Developer

“A Drupal developer is someone who writes a lot of PHP and other server side languages. They write custom modules, automated tests, consume web services, automate deployment etc. They may also be know as “backend Drupal developers”. They may also get involved in some of the more advanced side of the theme layer as well.” (source)

Freelance Delphi Developer

A Delphi developer creates code in the Delphi programming language. “Delphi is a high-level programming language distributed by Embarcadero Technologies as part of RAD Studio, an IDE for professional developers. It is primarily used to build applications for Windows systems but can be used to build applications for a variety of operating systems.” (source)

Freelance Oracle Developer

“An Oracle developer is responsible for creating or maintaining the database components of an application that uses the Oracle technology stack. Oracle developers either develop new applications or convert existing applications to run in an Oracle Database environment.” (source)


Do you want to develop the skills of a well-rounded Python professional—while getting paid in the process? Become a Python freelancer and order your book Leaving the Rat Race with Python on Amazon (Kindle/Print)!

Leaving the Rat Race with Python Book

Where to Go From Here?

Enough theory, let’s get some practice!

To become successful in coding, you need to get out there and solve real problems for real people. That’s how you can become a six-figure earner easily. And that’s how you polish the skills you really need in practice. After all, what’s the use of learning theory that nobody ever needs?

Practice projects is how you sharpen your saw in coding!

Do you want to become a code master by focusing on practical code projects that actually earn you money and solve problems for people?

Then become a Python freelance developer! It’s the best way of approaching the task of improving your Python skills—even if you are a complete beginner.

Join my free webinar “How to Build Your High-Income Skill Python” and watch how I grew my coding business online and how you can, too—from the comfort of your own home.

Join the free webinar now!

The post Freelance Developers Specialize! But Where? first appeared on Finxter.

Posted on Leave a comment

Overriding in Python

In this article, we are going to explore the concept of overriding in Python. We are also going to explore what are magic methods and abstract classes.

Introduction

Overriding is an interesting concept in object-oriented programming.  When the method definitions of a Base Class are changed in a Subclass (Derived) Class this is called a method override.  You are keeping the same signature of the method but changing the definition or implementation of a method defined by one of the ancestors.  There is no special syntax or additional keywords needed to do method overriding in Python.  It is a very important object-oriented programming concept since it makes inheritance exploit its full power.  In essence, you are not duplicating code, thus following the programming principle of DRY (do not repeat yourself), and you can enhance the method in the subclass.

To understand the concept of overrides, you must know the basic concepts of object-oriented programming such as classes and inheritance.  There are many resources on the internet about OOP.  A really good resource is Finxter Academy’s object-oriented Python class: https://academy.finxter.com/university/object-oriented-python/

Need for Overrides

In the following example, you see how inheritance works and the problem of not overriding a method in the subclass.  The Parent class has a method whoami that displays “I am a parent”.  This method is inherited by the Child class.  Calling the whoami method from the Child class, calls the inherited method from the Parent class and thus displays “I am a parent” which is wrong.

Inheritance example with no method overriding:

class Parent(): def whoami(self): print("I am a parent") class Child(Parent): def play(self): print(" I am playing") child = Child()
child.whoami() # Output:
# I am a parent

Basic Override

The next example, shows how basic overriding works.  In this example the Child class has a definition of the whoami method that overrides the method from the Parent class. Calling the whoami method from the Child class now displays “I am a child”.

Basic Overriding example:

#Overriding
class Parent(): def whoami(self): print("I am a parent") class Child(Parent): def play(self): print(" I am playing") def whoami(self): print("I am a child") parent = Parent()
parent.whoami()
print()
child = Child()
child.whoami() # Output:
# I am a parent
# I am a child

Extending a Method Through Overrides

The third example shows how you can extend a method in a Base Class by overriding the method in the Subclass.  To do that we use the super() built-in function.  It returns a proxy object that allows us to access methods of the base class.  We can refer to the base class from the subclass without having to call the base class name explicitly.

The Employee class has the following details for the employee: employee number, employee name, salary and, department number.  This information is passed to the instantiated object in the __init__ method.  The showEmployee method of the class then displays this information formatted using new lines.

The Salesman class inherits from the Employee class.  By default, it inherits the showEmployee method as-is from the Employee class.  The only problem is that we want to display the commission that the salesman receives as part of the printed information.  Here is where overriding is needed.  We want to reuse the showEmployee method from the Employee class but we want to extend it to add the commission information.  This is accomplished by using the super() built-in function.  In the example below you see that in the Salesman class, super() is used twice.  The __init__ method uses it to call the __init__ method of the Employee base class and the showEmployee uses it to override the showEmployee method of the Employee base class.  In it, we display the employee information for the salesman plus the commission for the salesman.

A third class called CEO uses the same logic as before.  The showEmployee method in this case displays the employee information plus the stock options for the CEO.

class Employee(): def __init__(self, empno, ename, salary, deptno): self.Empno = empno self.Ename = ename self.Salary = salary self.Deptno = deptno def showEmployee(self): print("Employee # : {}\nEmployee Name : {}\nSalary : {}\nDepartment : {}".format(self.Empno, self.Ename, self.Salary, self.Deptno)) class Salesman(Employee): def __init__(self, empno, ename, salary, deptno, comm): self.Commission = comm super().__init__(empno, ename, salary, deptno) def showEmployee(self): print("Salesman Profile") super().showEmployee() print("Commision : ", self.Commission) class CEO(Employee): def __init__(self, empno, ename, salary, deptno, stock): self.Stock = stock super().__init__(empno, ename, salary, deptno) def showEmployee(self): print("CEO Profile") super().showEmployee() print("Stock Options : ", self.Stock) salesman = Salesman(200, "John Doe", 67000, "Sales", 100)
salesman.showEmployee()
print("")
ceo = CEO(40, "Jennifer Smith", 300000, "Director", 1000000)
ceo.showEmployee() 

Output:

Salesman Profile
Employee # : 200
Employee Name : John Doe
Salary : 67000
Department : Sales
Commision : 100 CEO Profile
Employee # : 40
Employee Name : Jennifer Smith
Salary : 300000
Department : Director
Stock Options : 1000000

Multiple Inheritance Overriding

Understanding multiple inheritance has its own challenges.  One of them is the use of super().  Here is a link to an article about this issue: https://www.datacamp.com/community/tutorials/super-multiple-inheritance-diamond-problem

In the example below, I wanted to show a way to override a method from a subclass with multiple inheritance.  The example consists of three classes: Account, Customer, and Orders

  • The Account class has its name and number and a display method which displays this information. 
  • The Customer class has also its name and number and a display method that displays this information. 
  • The Orders class displays the orders information for a customer in a specific account.  It inherits from both the Account and Orders class.  The display method in this class overrides the display methods of the base classes.  The display method prints the Account information, the Customer information, and the Orders information

Here’s an example:

class Account(): def __init__(self, name, number): self.Name = name self.Number = number def display(self): print("Account # : {}\nAccount Name : {}".format(self.Number, self.Name)) class Customer(): def __init__(self, name, number): self.Name = name self.Number = number def display(self): print("Customer # : {}\nCustomer Name : {}".format(self.Number, self.Name)) class Orders(Account, Customer): def __init__(self, acctnumber, acctname, custnumber, custname, ordnumber, ordnamename, product, qty): self.OrdNumber = ordnumber self.Product = product self.Qty = qty self.OrdName = ordnamename self.acct = Account(acctname, acctnumber) self.cust = Customer(custname, custnumber) def display(self): print("Order Information") self.acct.display() self.cust.display() print("Order # : {}\nOrder Name : {}\nProduct : {}\nQuantiy : {}".format(self.OrdNumber, self.OrdName, self.Product, self.Qty)) acct = Account("AB Enterprise", 12345)
acct.display()
print("")
cust = Customer("John Smith", 45678)
cust.display()
print("")
order = Orders(12345, "AB Enterprise", 45678,"John Smith", 1, "Order 1", "Widget", 5, )
order.display()

Output:

Account # : 12345
Account Name : AB Enterprise Customer # : 45678
Customer Name : John Smith Order Information
Account # : 12345
Account Name : AB Enterprise
Customer # : 45678
Customer Name : John Smith
Order # : 1
Order Name : Order 1
Product : Widget
Quantiy : 5

Different Overriding Scenarios

1 – Class Methods

Class methods are special in the sense that they can be called on a class by itself or by instances of a class.  They bind to a class so this means that the first argument passed to the method is a class rather than an instance.

Class methods are written similarly to regular instance methods.  One difference is the use of the decorator @classmethod to identify that the method is a class method.  Also, by convention, instead of using self to reference the instance of a class, cls is using to reference the class.  For example:

class Account(): @classmethod def getClassVersion(cls): print("Account class version is 1.0”)

For more information about class methods check this website.

Here is an example of the problem you will encounter when overriding a class method:

class ParentClass: @classmethod def display(cls, arg): print("ParentClass") class SubClass(ParentClass): @classmethod def display(cls, arg): ret = ParentClass.create(cls, arg) print("Subclass") return ret SubClass.display("test")

Output:

create() takes 2 positional arguments but 3 were given

In the Subclass, the call to the ParentClass create method is not an unbound call the way it happens with a normal instance method.  The outcome of this call is a TypeError because the method received too many arguments.

The solution is to use super() in order to successfully use the parent implementation.

class ParentClass: @classmethod def display(cls, arg): print("ParentClass") class SubClass(ParentClass): @classmethod def display(cls, arg): ret = super(SubClass, cls).create(arg) print("Subclass") return ret SubClass.display("test")

Output:

ParentClass
Subclass

2 – Magic Methods

What are magic methods?

Magic methods are a set of methods that Python automatically associates with every class definition. Your classes can override these magic methods to implement different behaviors and make them act just like Python’s built-in classes. Below you will see examples of two of the most common ones: __str__ and __repl__. Using these two methods, you can implement how your objects are displayed as strings, which will be of importance while debugging and presenting the information to the user.  Overriding these methods adds to the flexibility and power of Python.  

The __str__ method of a class is used when Python prints an object. This magic method is called by the str built-in function.

class DemoMagic(): def display(self): print("Demo Magic class") varDemo = DemoMagic()
varDemo.display()
str(varDemo) 

Output:

Demo Magic class '<__main__.DemoMagic object at 0x000002A7A7F64408>' class DemoMagic():
def display(self): print("Demo Magic class") def __str__(self): return "Override of str function" varDemo = DemoMagic()
varDemo.display()
str(varDemo) 

Output:

Demo Magic class 'Override of str function'

The __repr__ method of a class is used to display the details of an object’s values. This magic method is called by the built-in the repr function.

class Person(object): def __init__(self, firstname, lastname): self.first = firstname self.last = lastname def __repr__(self): return "%s %s" % (self.first, self.last) Tom = Person("Tom", "Sawyer")
repr(Tom)

Output

'Tom Sawyer'

Here is a list of magic methods.  You can learn more about them here (https://www.tutorialsteacher.com/python/magic-methods-in-python) and think how to override them to fit your needs:

'__abs__', '__add__', '__and__', '__bool__', '__ceil__', '__class__', '__delattr__', '__dir__', '__divmod__', '__doc__', '__eq__', '__float__', '__floor__', '__floordiv__', '__format__', '__ge__', '__getattribute__', '__getnewargs__', '__gt__', '__hash__', '__index__', '__init__', '__init_subclass__', '__int__', '__invert__', '__le__', '__lshift__', '__lt__', '__mod__', '__mul__', '__ne__', '__neg__', '__new__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', '__round__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', '__rxor__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__truediv__', '__trunc__', '__xor__'

3 – Abstract Classes  

An abstract class is a blueprint that subclasses must follow.  It can be viewed as a contract between the abstract class and the subclass.  The abstract class tells you what to do by providing an empty abstract method and the subclass must implement it.  By default, you must override the abstract methods defined by the abstract class.  In other terms, we are providing a common interface for different implementations of a class.  This is very useful for large projects where certain functionality must be implemented.

Here is an example of an abstract class and the overrriden methods in the subclasses.

from abc import ABC, abstractmethod class Animal(ABC): @abstractmethod def whoami(self): pass class Dog(Animal): def move(self): print("I am a dog") class Cat(Animal): def move(self): print("I am a cat") 

Conclusion

Overriding is a basic concept used in many places in object-oriented programming.  You must understand it to be able to implement better classes and modify their behavior.  This article shows you some examples where you can use overrides in Python.  Other concepts mentioned that are worth learning more about are: magic method and abstract classes.

The post Overriding in Python first appeared on Finxter.

Posted on Leave a comment

gRPC performance improvements in .NET 5

Avatar

James

gRPC is a modern open source remote procedure call framework. There are many exciting features in gRPC: real-time streaming, end-to-end code generation, and great cross-platform support to name a few. The most exciting to me, and consistently mentioned by developers who are interested in gRPC, is performance.

Last year Microsoft contributed a new implementation of gRPC for .NET to the CNCF. Built on top of Kestrel and HttpClient, gRPC for .NET makes gRPC a first-class member of the .NET ecosystem.

In our first gRPC for .NET release, we focused on gRPC’s core features, compatibility, and stability. In .NET 5, we made gRPC really fast.

gRPC and .NET 5 are fast

In a community run benchmark of different gRPC server implementations, .NET gets the highest requests per second after Rust, and is just ahead of C++ and Go.

gRPC performance comparison

This result builds on top of the work done in .NET 5. Our benchmarks show .NET 5 server performance is 60% faster than .NET Core 3.1. .NET 5 client performance is 230% faster than .NET Core 3.1.

Stephen Toub discusses dotnet/runtime changes in his Performance Improvements in .NET 5 blog post. Check it out to read about improvements in HttpClient and HTTP/2.

In the rest of this blog post I’ll talk about the improvements we made to make gRPC fast in ASP.NET Core.

HTTP/2 allocations in Kestrel

gRPC uses HTTP/2 as its underlying protocol. A fast HTTP/2 implementation is the most important factor when it comes to performance. Our gRPC server builds on top of Kestrel, a HTTP server written in C# that is designed with performance in mind. Kestrel is a top contender in the TechEmpower benchmarks, and gRPC benefits from a lot of the performance improvements in Kestrel automatically. However, there are many HTTP/2 specific optimizations that were made in .NET 5.

Reducing allocations is a good place to start. Fewer allocations per HTTP/2 request means less time doing garbage collection (GC). And CPU time “wasted” in GC is CPU time not spent serving HTTP/2 requests.

.NET Core 3.1 memory graph

The performance profiler above is measuring allocations over 100,000 gRPC requests. The live object graph’s sawtooth shaped pattern indicates memory building up, then being garbage collected. About 3.9KB is being allocated per request. Lets try to get that number down!

dotnet/aspnetcore#18601 adds pooling of streams in a HTTP/2 connection. This one change almost cuts allocations per request in half. It enables reuse of internal types like Http2Stream, and publicly accessible types like HttpContext and HttpRequest, across multiple requests.

Once streams are pooled a range of optimizations become available:

There are many smaller allocation savings. dotnet/aspnetcore#19783 removes allocations in Kestrel’s HTTP/2 flow control. A resettable ManualResetValueTaskSourceCore<T> type replaces allocating a new object each time flow control is triggered. dotnet/aspnetcore#19273 replaces an array allocation with stackalloc when validating the HTTP request path. dotnet/aspnetcore#19277 and dotnet/aspnetcore#19325 eliminate some unintended allocations related to logging. dotnet/aspnetcore#22557 avoids allocating a Task<T> if a task is already complete. And finally dotnet/aspnetcore#19732 saves a string allocation by special casing content-length of 0. Because every allocation matters.

.NET 5 memory

Per-request memory in .NET 5 is now just 330 B, a decrease of 92%. The sawtooth pattern has also disappeared. Reduced allocations means garbage collection didn’t run at all while the server processed 100,000 gRPC calls.

Reading HTTP headers in Kestrel

A hotpath in HTTP/2 is reading and writing HTTP headers. A HTTP/2 connection supports concurrent requests over a TCP socket, a feature called multiplexing. Multiplexing allows HTTP/2 to make efficient use of connections, but only the headers for one request on a connection can be processed at a time. HTTP/2’s HPack header compression is stateful and depends on order. Processing HTTP/2 headers is a bottleneck so has to be as fast as possible.

dotnet/aspnetcore#23083 optimizes the performance of HPackDecoder. The decoder is a state machine that reads incoming HTTP/2 HEADER frames. The approach here is good, the state machine allows Kestrel to decode frames as they arrive, but the decoder was checking state after parsing each byte. Another problem is literal values, the header names and values, were copied multiple times. Optimizations in this PR include:

  • Tighten parsing loops. For example, if we’ve just parsed a header name then the value must come afterwards. There is no need to check the state machine to figure out the next state.
  • Skip literal parsing all together. Literals in HPack have a length prefix. If we know the next 100 bytes are a literal then there is no need to inspect each byte. Mark the literal’s location and resuming parsing at its end.
  • Avoid copying literal bytes. Previously literal bytes were always copied to an intermediary array before passed to Kestrel. Most of the time this isn’t necessary and instead we can just slice the original buffer and pass a ReadOnlySpan<byte> to Kestrel.

Together these changes significantly decrease the time it takes to parse headers. Header size is almost no longer a factor. The decoder marks the start and end position of a value and then slices that range.

private HPackDecoder _decoder = CreateDecoder();
private byte[] _smallHeader = new byte[] { /* HPack bytes */ };
private byte[] _largeHeader = new byte[] { /* HPack bytes */ };
private IHttpHeadersHandler _noOpHandler = new NoOpHeadersHandler(); [Benchmark]
public void SmallDecode() => _decoder.Decode(_smallHeader, endHeaders: true, handler: _noOpHandler); [Benchmark]
public void LargeDecode() => _decoder.Decode(_largeHeader, endHeaders: true, handler: _noOpHandler);
Method Runtime Mean Ratio Allocated
SmallDecode .NET Core 3.1 111.20 ns 1.00 0 B
SmallDecode .NET 5.0 71.90 ns 0.65 0 B
LargeDecode .NET Core 3.1 49,083.00 ns 1.00 0 B
LargeDecode .NET 5.0 98.68 ns 0.002 0 B

Once headers have been decoded, Kestrel needs to validate and process them. For example, special HTTP/2 headers like :path and :method need to be set onto HttpRequest.Path and HttpRequest.Method, and other headers need to be converted to strings and added to the HttpRequest.Headers collection.

Kestrel has the concept of known request headers. Known headers are a selection of commonly occuring request headers that have been optimized for fast setting and getting. dotnet/aspnetcore#24730 adds an even faster path for setting HPack static table headers to the known headers. The HPack static table gives 61 common header names and values a number ID that can be sent instead of the full name. A header with a static table ID can use the optimized path to bypass some validation and quickly be set in the collection based on its ID. dotnet/aspnetcore#24945 adds extra optimization for static table IDs with a name and value.

Adding HPack response compression

Prior to .NET 5, Kestrel supported reading HPack compressed headers in requests, but it didn’t compress response headers. The obvious advantage of response header compression is less network usage, but there are performance benefits as well. It’s faster to write a couple of bits for a compressed header than it is to encode and write the header’s full name and value as bytes.

dotnet/aspnetcore#19521 adds initial HPack static compression. Static compression is pretty simple: if the header is in the HPack static table then write the ID to identify the header instead of the longer name.

Dynamic HPack header compression is more complicated, but also provides bigger gains. Response header names and values are tracked in a dynamic table and are each assigned an ID. As a response’s headers are written, the server checks to see if the header name and value are in the table. If there is a match then the ID is written. If there isn’t then the full header is written, and it is added to the table for the next response. There is a maximum size of the dynamic table, so adding a header to it may evict other headers with a first in, first out order.

dotnet/aspnetcore#20058 adds dynamic HPack header compression. To quickly search for headers the dynamic table groups header entries using a basic hash table. To track order and evict the oldest headers, entries maintain a linked list. To avoid allocations, removed entries are pooled and reused.

Wireshark HTTP/2 response

Using Wireshark, we can see the impact of header compression on response size for this example gRPC call. .NET Core 3.x writes 77 B, while .NET 5 is only 12 B.

Protobuf message serialization

gRPC for .NET uses the Google.Protobuf package as the default serializer for messages. Protobuf is an efficient binary serialization format. Google.Protobuf is designed for performance, using code generation instead of reflection to serialize .NET objects. There are some modern .NET APIs and features that can be added to it to reduce allocations and improve efficiency.

The biggest improvement to Google.Protobuf is support for modern .NET IO types: Span<T>, ReadOnlySequence<T> and IBufferWriter<T>. These types allow gRPC messages to be serialized directly using buffers exposed by Kestrel. This saves Google.Protobuf allocating an intermediary array when serializing and deserializing Protobuf content.

Support for Protobuf buffer serialization was a multi-year effort between Microsoft and Google engineers. Changes were spread across multiple repositories.

protocolbuffers/protobuf#7351 and protocolbuffers/protobuf#7576 add support for buffer serialization to Google.Protobuf. This is by far the biggest and most complicated change. Three attempts were made to add this feature before the right balance between performance, backwards compatibility and code reuse was found. Protobuf reading and writing uses many performance oriented features and APIs added to C# and .NET Core:

  • Span<T> and C# ref struct types enables fast and safe access to memory. Span<T> represents a contiguous region of arbitrary memory. Using span lets us serialize to managed .NET arrays, stack allocated arrays, or unmanaged memory, without using pointers. Span<T> and .NET protects us against buffer overflow.
  • stackalloc is used to create stack-based arrays. stackalloc is a useful tool to avoid allocations when a small buffer is required.
  • Low-level methods such as MemoryMarshal.GetReference(), Unsafe.ReadUnaligned() and Unsafe.WriteUnaligned() convert directly between primitive types and bytes.
  • BinaryPrimitives has helper methods for efficiently converting between .NET primitive types and bytes. For example, BinaryPrimitives.ReadUInt64LittleEndian reads little endian bytes and returns an unsigned 64 bit number. Methods provided by BinaryPrimitive are heavily optimized and use vectorization.

A great thing about modern C# and .NET is it is possible to write fast, efficient, low-level libraries without sacrificing memory safety. When it comes to performance, .NET lets you have your cake and eat it too!

private TestMessage _testMessage = CreateMessage();
private ReadOnlySequence<byte> _testData = CreateData();
private IBufferWriter<byte> _bufferWriter = CreateWriter(); [Benchmark]
public IMessage ToByteArray() => _testMessage.ToByteArray(); [Benchmark]
public IMessage ToBufferWriter() => _testMessage.WriteTo(_bufferWriter); [Benchmark]
public IMessage FromByteArray() => TestMessage.Parser.ParseFrom(CreateBytes()); [Benchmark]
public IMessage FromSequence() => TestMessage.Parser.ParseFrom(_testData);
Method Runtime Mean Ratio Allocated
ToByteArray .NET 5.0 1,133.82 ns 1.00 184 B
ToBufferWriter .NET 5.0 589.05 ns 0.51 64 B
FromByteArray .NET 5.0 409.88 ns 1.00 1960 B
FromSequence .NET 5.0 381.03 ns 0.92 1776 B

Adding support for buffer serialization to Google.Protobuf is just the first step. More work is required for gRPC for .NET to take advantage of the new capability:

  • grpc/grpc#18865 and grpc/grpc#19792 adds ReadOnlySequence<byte> and IBufferWriter<byte> APIs to the gRPC serialization abstraction layer in Grpc.Core.Api.
  • grpc/grpc#23485 updates gRPC code generation to glue the changes in Google.Protobuf to Grpc.Core.Api.
  • grpc/grpc-dotnet#376 and grpc/grpc-dotnet#629 updates gRPC for .NET to use the new serialization abstractions in Grpc.Core.Api. This code is the integration between Kestrel and gRPC. Because Kestrel’s IO is built on top of System.IO.Pipelines, we can use its buffers during serialization.

The end result is gRPC for .NET serializes Protobuf messages directly to Kestrel’s request and response buffers. Intermediary array allocations and byte copies have been eliminated from gRPC message serialization.

Wrapping Up

Performance is a feature of .NET and gRPC, and as cloud apps scale it is more important than ever. I think all developers can agree it is fun to make fast apps, but performance has real world impact. Lower latency and higher throughput means fewer servers. It is an opportunity to save money, reduce power use and build greener apps.

.NET Core 3.1 vs .NET 5 results

As is obvious from this tour, a lot of changes have gone into gRPC, Protobuf and .NET aimed at improving performance. Our benchmarks show a 60% improvement in gRPC server RPS and a 230% improvement in gRPC client RPS.

.NET 5 RC2 is available now, and the official .NET 5 release is in November. To try out the performance improvements and to get started using gRPC with .NET, the best place to start is the Create a gRPC client and server in ASP.NET Core tutorial.

We look forward to hearing about apps built with gRPC and .NET, and to your future contributions in the dotnet and grpc repos!

Posted on Leave a comment

Freelance Developer LLC — Is It Smart For You?

Should you create an LLC as a freelance developer?

In this article, you’ll learn about which clothes your freelancing business should wear. Make no mistake—choosing the right business entity matters. And informing about this question by reading articles like this one may be one of the most important decisions in your professional life.

Disclaimer: I’m not an accountant but a programmer—so, you should consult with your accountant or lawyer before taking any conclusive action!

Definition LLC

“A limited liability company (LLC) is a business structure in the United States whereby the owners are not personally liable for the company’s debts or liabilities. Limited liability companies are hybrid entities that combine the characteristics of a corporation with those of a partnership or sole proprietorship.” (source)

So, if you create an LLC, you are generally not liable for any debt or liabilities of your freelancing business. Most likely, your freelancing business doesn’t need a lot of debt—after all, you’re selling your time for money—however, there may still be liabilities!

For example, you may have signed a contract that requires you to pay for all damages incurred by your software. Yes, you shouldn’t have done it—but assuming you have, if you signed in the name of the LLC, you personally cannot be hold accountable for the potentially devastating liabilities.

Pros vs Cons Table

What are some advantages and disadvantages of a liability?

LLC Pros LLC Cons
Limited Liability – If you keep your finances separate and fullfil your duties as a business owner, you cannot be personally held liable. Your personal assets like real estate, stocks, bonds, mutual funds will remain protected even if your business fails. Limitations of Limited Liability – this is called “piercing the corporate veil” and it means that if you don’t follow the rules of the LLC, a judge may decide that your liability protection will be removed and you, personally, can be held liable.
Pass-Through Federal Taxation on Profits – Per default, the profits are not taxed on the company level but are passed through to its owners who then tax them individually. This is an advantage if you have a relatively lower tax rate and it avoids double taxation on the corporate and individual level. Self-Employment Tax – Per default, you must pay self-employment taxes on the profits of an LLC because it is a pass-through entity.
Management Flexibility – The LLC can be managed by one or more owners. This is a perfect structure for partnerships where ownership percentages can be divided in a flexible way. Turnover – If an LLC partner dies, goes bankrupt, or leaves the company, the company will be dissolved. You need to create a new one and you take over all the leaving partners’ obligations that result in dissolving the LLC.
Easy Startup Overhead – It’s relatively simple and cheap—a few hundred dollars—to start an LLC. For the amount of protection it offers, it’s a very cheap way to organize your freelancing business. Investments – It’s difficult to raise outside capital. This is usually not a problem for you as a freelance developer because freelance developing has only minimal capital requirements.
Unproportional Profit Distribution – Members can receive profits that are not proportional to the ownership percentage they hold. This allows you to reinforce members for great work.
Credibility – Being an LLC gives you more credibility as a freelance developer. Clients tend to trust you more, as a freelance developer organized in an LLC, for two reasons: you’re an US-based business and you’re a serious business.

Sources:

Freelancer LLC Taxes

An LLC isn’t a federal tax designation but there’s a pass-through federal taxation on profits. This means that in most states, LLC aren’t taxed at all but the individuals who own them are. In other words, your tax designation is that of a disregarded entity that files taxes the same as a sole proprietor.

As a freelance developer, you probably don’t want to leave a lot of profits in the business, so the fact that it is pass-through doesn’t bother you at all. If you would like to build a business machine based on smart reinvestments of profits, feel free to read my detailed article about the topic or watch the following video:

Sources:

Freelancer LLC or Sole Proprietorship

Sole proprietorship is the freelancer’s default business entity. If you don’t explicitly form an LLC or corporation, you’ll automatically operate as a sole proprietor. The main advantage of LLCs compared to Sole Proprietorships are that you’re generally not liable for debts or liabilities of your freelancing business. This protects your personal assets and reduces the likelihood of a personal bankruptcy in case of unforeseen liabilities that happened because of your business activities.

You can read more about the best legal entity for your freelancing business here.

Freelancer LLC or S-Corp

Per default, single-member LLCs are automatically taxed like sole proprietors as pass-through entities. The business isn’t taxed but you are. The S-Corp is just an alternative way you can choose to get taxed: You ask the IRS to tax your single-member LLC as an S-Corp. As a result, you don’t have to pay self-employment taxes anymore—but only income taxes on the corporate profits. This has a few advantages such as the tax deductability of the self-employment tax from corporate profits and the possibility to tax only a smaller portion of the overall profits.

You can read more in this excellent article:

Source: https://www.collective.com/blog/business-setup/llc-vs-s-corp-which-is-the-best-for-freelancers/

Freelancer LLC Names

As a freelance developer, you need to decide on a business name. There are two types of restrictions: First, you cannot choose names that are already trademarked—or that are similar to trademarked names. Second, you cannot choose names that are already taken by other businesses. If you choose your business as your personal name, you usually don’t run into any legal problem. Some people argue that this can harm your scalability or prospects to sell the business. However, as a freelance developer, this is usually not a problem as you’d create a separate business for more scalable ventures anyways.

Delaware LLC Freelancer

Can you create a Delaware corporation as a freelance developer? According to international tax lawyer Jason Knott, the answer is: “Yes, a nonresident can form an entity in Delaware or almost any other state in the U.S.” If you succeed as a freelance developer creating a Delaware LLC, you reduce or even eliminate your income tax burden. However, this can be a complicated legal procedure and you should definitely seek expert advice.

Where to Go From Here?

Enough theory, let’s get some practice!

To become successful in coding, you need to get out there and solve real problems for real people. That’s how you can become a six-figure earner easily. And that’s how you polish the skills you really need in practice. After all, what’s the use of learning theory that nobody ever needs?

Practice projects is how you sharpen your saw in coding!

Do you want to become a code master by focusing on practical code projects that actually earn you money and solve problems for people?

Then become a Python freelance developer! It’s the best way of approaching the task of improving your Python skills—even if you are a complete beginner.

Join my free webinar “How to Build Your High-Income Skill Python” and watch how I grew my coding business online and how you can, too—from the comfort of your own home.

Join the free webinar now!

The post Freelance Developer LLC — Is It Smart For You? first appeared on Finxter.

Posted on Leave a comment

How to Install PIL/Pillow in Python? A Helpful Illustrated Guide

PIL is an abbreviation of Python Imaging Library and it adds image processing to Python. In 2011, PIL has been discontinued—its unofficial successor framework Pillow for image processing is an actively maintained and user-friendly alternative for Python 3.

Install Pillow Command Line Windows
pip install Pillow

Let’s dive into the installation guides for the different operating systems and environments!

How to Install Pillow on Windows?

To install the updated Pillow framework on your Windows machine, run the following code in your command line or Powershell:

python3 -m pip install --upgrade pip
python3 -m pip install --upgrade Pillow

How to Install Pillow on Mac?

Open Terminal (Applications/Terminal) and run:

  • xcode-select -install (You will be prompted to install the Xcode Command Line Tools)
  • sudo easy_install pip
  • sudo pip install pillow
  • pip install pillow

As an alternative, you can also run the following two commands to update pip and install the Pillow library:

python3 -m pip install --upgrade pip
python3 -m pip install --upgrade Pillow

How to Install Pillow on Linux?

Upgrade pip and install the Pillow library using the following two commands, one after the other:

python3 -m pip install --upgrade pip
python3 -m pip install --upgrade Pillow

How to Install Pillow on Ubuntu?

Upgrade pip and install the Pillow library using the following two commands, one after the other:

python3 -m pip install --upgrade pip
python3 -m pip install --upgrade Pillow

How to Install Pillow in PyCharm?

The simplest way to install Pillow in PyCharm is to open the terminal tab and run the following command:

pip install Pillow

Here’s a screenshot with the two steps:

  • Open Terminal tab in Pycharm
  • Run pip install Pillow in the terminal to install Pillow in a virtual environment.
Install Pillow

As an alternative, you can also search for Pillow in the package manager. However, this is usually an inferior way to install packages because it involves more steps.

How to Install Pillow in Anaconda?

You can install the Pillow package with Conda using the following command in your shell:

 conda install -c anaconda pillow 

This assumes you’ve already installed conda on your computer. If you haven’t check out the installation steps on the official page.

Where to Go From Here?

Enough theory, let’s get some practice!

To become successful in coding, you need to get out there and solve real problems for real people. That’s how you can become a six-figure earner easily. And that’s how you polish the skills you really need in practice. After all, what’s the use of learning theory that nobody ever needs?

Practice projects is how you sharpen your saw in coding!

Do you want to become a code master by focusing on practical code projects that actually earn you money and solve problems for people?

Then become a Python freelance developer! It’s the best way of approaching the task of improving your Python skills—even if you are a complete beginner.

Join my free webinar “How to Build Your High-Income Skill Python” and watch how I grew my coding business online and how you can, too—from the comfort of your own home.

Join the free webinar now!

The post How to Install PIL/Pillow in Python? A Helpful Illustrated Guide first appeared on Finxter.