フルスタック開発: JavaScript 開発者としての Python の学習

WBOY
リリース: 2024-08-31 00:22:33
オリジナル
303 人が閲覧しました

Fullstack Development: Learning Python as JavaScript Developers

旅の始まり

私はフロントエンド開発者として 8 年以上働いてきましたが、ここ 2 年間で自分のキャリアとどのように成長できるかを再考することにしました。フロントエンド テクノロジは頻繁に変更され、さまざまなフレームワーク、コンセプト、React クラスのコンポーネントとフックの間のギャップがあることがわかりました。これらはすべて、ビジネスのニーズや個人のビジョンを表現するために使用される抽象的なものにすぎないことに気づきました。この時点から、私はキャリアパスを少し変更して、フルスタック開発者になることに決めました。

誰もが知っているように、最近のフロントエンド開発は JavaScript がすべてです。そのため、私は Node.js とその主要なフレームワークを学ぶことにしました。すべてのフロントエンド開発者は何らかの形で Node.js に遭遇します。上級フロントエンド開発者であれば、Express または別のライブラリを使用して Node.js で基本的なエンドポイントを作成できるはずです。 Node.js 側で 2 年間積極的に開発を行った後、私の仕事がフロントエンドとバックエンドで 50/50 になったとき、ほとんどのプロジェクトが 1 つの言語に限定されていないことがわかりました。

Node.js は、特に大企業で働いている場合には、すべてに最適なツールというわけではありません。言語が異なれば、提供されるソリューションも異なります。また、特定のビジネス ケースを解決するのに最適な言語もあります。これが、私が 2 番目のバックエンド言語として何を学べ、それを将来どのように活用できるかを研究し始めた理由です。

私の経験と、Rust (主に Web 開発用ではない)、Swift (主にモバイルファーストのソリューション)、Golang を学ぼうとした後で Python にこだわることに決めた理由を共有したいと思います。ここでは、フロントエンド開発者にとって Python が学習の素晴らしい機会であると私が考える理由と、Python を使い始める方法について説明します。

なぜパイソンなのか?

今日、AI について誰もが話題にしています。面接で経験の一部としてそれを言及すると、常に追加ポイントが与えられます。ほぼすべての企業が自社の製品に AI を組み込もうとしていますが、Python は AI や機械学習と密接に関係しています。 Python を学習すると、Django、Flask、FastAPI などのフレームワークを使用して Web アプリケーションを作成する機会が得られるだけでなく、機械学習や AI サービスの操作を開始することもできます。
一方で、より優れたプログラマーになりたい場合は、Rust、Go、Elixir などのより複雑な言語を学ぶことは良い考えです。ただし、キャリアの観点から見ると、あまり馴染みのない、まったく異なる言語を使用するバックエンド開発者になるのは簡単ではありません。

Python は動的に型付けされたプログラミング言語です。キャリアの大部分を同様の環境で過ごしてきた JavaScript 開発者としては、コード内でどのような種類の問題が予想されるかをすでに知っているので、これに怯える必要はありません。
Python を使用すると、Web アプリケーションの作成を開始できるだけでなく、AI 関連分野でのスキルを活用することもできるため、Python は第 2 言語として大きな利点をもたらします。

学習曲線

学習曲線は簡単でした。 Python では、必ずいくつかの基本概念を学ぶ必要があります。 JavaScript の経験がある場合は、それほど大きな問題ではないはずです。

Python のコード例は次のとおりです:

リーリー

ここではそれほど複雑なことはないと思います。これまでに Python を学習したことがなくても、ドキュメントを読まなくてもほぼすべての行を理解できます。

あなたが気づく最大の違いは、Python が中括弧の代わりにインデントを使用してコード ブロックを定義していることです。奇妙に思えるかもしれませんし、私も今でも少し珍しいと思いますが、しばらくすると慣れて、コードを読むのが簡単になります。

それとは別に、Python の多くの概念は JavaScript の概念と似ています。 console.log の代わりに print を使用できます。文字列補間の場合は、文字列の先頭に f を追加して、JavaScript とほぼ同じ構文を使用できます。

上記のコードの JavaScript バージョンは次のとおりです。

リーリー

障害の克服: 重要な概念

Python ではさまざまな概念を学ぶことができます。 JavaScript 開発者として私にとって最も混乱するものを示しました。

インデントベースの構文

JavaScript 開発者であれば、if/else やその他の演算子でコード ブロックを使用する方法に精通しているかもしれません。ほとんどの場合、{} を追加するだけで完了です。 Python のインデントベースのシステムは扱いにくい場合があります。

JavaScript コードを見てみましょう:

リーリー

Python アナログ:

if role == "admin": posts = get_draft_posts() if posts.length == 0: raise NotFound() return posts
ログイン後にコピー

As you can see readability of blocks in Python could be challenging from the first view. This is why for me it was important to avoid deeply nested blocks because it is hard to read and easy to miss correct indention. Keep in mind that Python could attach your code to a wrong code block because of missed indention.

Type system

Python is a dynamic typing language but I was surprised to find Python built-in Types annotation.

def add(x: int, y: int) -> int: return x + y
ログイン後にコピー

You don’t need to install additional features, only what you need in Python *3.5 and above.*

Even more complex types could be described as equal to Typescript:

# enums from enum import Enum # import enum for built in lib class Season(Enum): # extend class to mark it as enum SPRING = 1 SUMMER = 2 AUTUMN = 3 WINTER = 4 print(Season.SPRING.name) # SPRING print(Season.SPRING.value) # 1 # or generics def first(container: List[T]) -> T: return container[0] list_two: List[int] = [1, 2, 3] print(first(list_two)) # 1
ログイン後にコピー

For using these types you are not required to install something or transpile this code. This is something I missed in JavaScript, at least Node.js. I know Node.js is adding some basic types in the nearest version (see Medium post about node.js built-in types support) but it looks poor now if you compare it with Python.

Python’s Global Interpreter Lock (GIL)

JavaScript uses an event-driven, non-blocking model, while Python's Global Interpreter Lock (GIL) can be a confusing concept in multi-threaded programs.
The Python Global Interpreter Lock (GIL) is a mechanism that ensures only one thread executes Python code at a time. Even if your Python program has multiple threads, only one thread can execute Python code at a time due to the GIL.
With JavaScript, you can achieve multithreading with web workers, but in Python, you need to use additional libraries to accomplish this.

A Pythonic Mindset

JavaScript's "multiple ways to do it" philosophy doesn't work as well in Python because Python adheres more closely to the concept "There should be one - and preferably only one - obvious way to do it."
In the JavaScript world, every company often creates its own code style guide, and it's fortunate if it follows basic JavaScript style recommendations. In reality, practices like using semicolons can vary widely, to the point where one project might use semicolons and another might not.
In Python, following Pythonic principles from PEP 8 (Python's style guide) is highly recommended. This guide outlines the basic rules of how to write Python code.
To write better code, it's essential to engage with the community and learn idiomatic Python practices that prioritize clarity and simplicity.

Managing Dependencies and Virtual Environments

This part might also be confusing. In JavaScript, you can usually add a package manager and start installing dependencies without any issues. However, Python’s pip and virtual environments may be new concepts.

In Python, when using additional dependencies, it’s highly recommended to use a separate virtual environment. Installing dependencies with pip (the Python equivalent of npm in JavaScript) in your environment could potentially break system utilities or the OS itself, as the system Python interpreter (the one that comes pre-installed with your operating system) is used by the OS and other system utilities.

As a solution, you can create a virtual environment with venv module:

python -m venv myenv myenv\Scripts\activate # for windows source myenv/bin/activate # for Mac
ログイン後にコピー

After you enter the virtual environment you can install all dependencies without any problem or danger for your root environment.

Finding Support and Resources

How I Learned Python

Learning a new language is always challenging. I started learning Python basics on an online platform, where I also completed some small projects. Here is the plan I used during my learning process:

  • Python basics.
  • Advanced Python concepts (module system, types, environment, async code).
  • Learning the basics of the most popular frameworks like Django, Flask, and FastAPI.
  • Writing my first API server with FastAPI.
  • Adding a database and learning how to work with databases in Python.
  • Deploying the application on a free hosting service.

Where to Find Help

You can find a lot of help in Reddit communities or Discord servers while learning. I’m mostly a Reddit user and would suggest finding subreddits for Python and the framework you decide to use for your first application.

Remember to use the official documentation. In my opinion, it looks overwhelming, and most of the time, I try to find related articles if I get stuck on a concept.

Make sure to readPEP 8 — Style Guide for Python Code, where you can find basic rules on how to write Python code.

過去とこれからを振り返って

JavaScript 開発者から Python を受け入れるまでの私の道のりを振り返ってみると、後悔はありません。この移行により、特に AI と機械学習の分野でエキサイティングな機会が開かれ、現在、私はこれらをプロジェクト、特にバックエンドで幅広く活用しています。

将来を見据えると、Python の可能性は膨大です。 Web 開発、データ サイエンス、自動化、または AI や機械学習の掘り下げのいずれであっても、Python は新しい地平を構築し探索するための強力で多用途の基盤を提供します。

以上がフルスタック開発: JavaScript 開発者としての Python の学習の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

ソース:dev.to
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!