Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to learn any programming language

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "how to learn any programming language". In daily operation, I believe many people have doubts about how to learn any programming language. Xiaobian consulted all kinds of materials and sorted out simple and easy operation methods. I hope to help you answer the doubts of "how to learn any programming language"! Next, please follow the small series to learn together!

1. syntax

Syntax

Language syntax describes the structure of the code. This includes how code is written line by line, as well as the actual words used to construct code statements.

Python, for example, is known for using indentation to indicate where one block of code ends and another begins:

while j

< rows: while k < columns: tile = Tile(k * w) board.add(tile) k += 1 j += 1 k = 0 Lua 只是使用关键字 end: for i,obj in ipairs(hit) do if obj.moving == 1 then obj.x,obj.y = v.mouse.getPosition() end end Java、C、C++ 之类的编程语言使用花括号: while (std::getline(e,r)) { wc++; } 编程语言的语法还包括包括库、设置变量和终止行等内容。通过练习,你将学会在阅读示例代码时下意识地识别语法需求(和惯例)。 实践 当学习一门新的编程语言时,要努力理解它的语法。你不需要去记住它,只需要知道如果忘记了以后去哪里查找。使用好的 IDE 也很有帮助,因为很多 IDE 在出现语法错误时会提醒你。 2. 内置函数和条件 built-in words 就像自然语言一样,编程语言可以识别的合法单词是有限的。这个词汇表可以使用其他库进行扩展,但是核心语言知道一组特定的关键字。大多数语言并没有你想的那么多关键字。即使在像 C 语言这样非常低级的语言中,也只有 32 个关键字,比如 for、do、while、int、float、char、break 等等。 了解了这些关键字,你就可以编写基本的表达式,也就是构建程序的代码块。许多内置的关键字能帮助你构建条件语句,这些条件语句影响整个程序的流程。例如,如果你想编写一个允许单击和拖动图标的程序,那么你的代码就必须检测用户的鼠标指针何时位于图标上。只有当鼠标光标位于图标外部边缘相同的坐标时,才执行导致使鼠标抓取图标的代码。这是一个经典的 if / then 语句,但不同的语言可以用不同的方式表达。 Python 使用 if、elif和 else 的组合来实现条件语句,但是并不显式的关闭语句: if var == 1: # action elif var == 2: # some action else: # some other action Bash 使用 if、elif、else,并且使用 fi 来结束语句: if [ "$var" = "foo" ]; then # action elif [ "$var" = "bar" ]; then # some action else # some other action fi 然而 C 和 Java, 使用 if、else 和 else if,用花括号把它们括起来: if (boolean) { // action } else if (boolean) { // some action } else { // some other action } 各种编程语言虽然在关键字的选择和语法上有细微的变化,但基本是相同的。学习如何在编程语言中定义条件语句,包括 if / then、do...while 和 case 语句。 实践 要熟悉编程语言能够理解的关键字集。在实践中,你的代码将不仅仅包含编程语言的关键字,可以肯定的是,有包含很多简单函数的库来帮助你做一些事情,诸如将输出打印到屏幕或显示窗口之类。然而,驱动这些库的逻辑始于编程语言的内置关键字。 3. 数据类型 Data types代码是用来处理数据的,因此你必须学习编程语言如何识别不同类型的数据。所有编程语言都能理解整数,大多数的语言能理解小数和单个字符(a、b、c 等等)。它们通常被表示为 int、 float、double 和 char,当然,语言的内置词汇表会告诉你如何引用这些实体。 有时候,在编程语言中内置了一些额外的数据类型,也有时是通过引用库来启用复杂的数据类型。例如,Python 可以识别关键字为 str 的字符串,但是 C 语言的代码中必须包含 string.h 头文件才能实现字符串特性。 实践 库可以为你的代码解锁各种类型的数据,但是学习编程语言中包含的基本数据类型是一个明智的起点。 4. 运算符和解析器 Operators一旦你理解了编程语言可处理的数据类型,就可以学习如何分析这些数据了。幸运的是,数学这门学科是相当稳定的,所以算数运算符在许多语言中通常是相同的(或至少非常相似)。例如,两个整数相加通常用 + 符号完成,而测试一个整数是否大于另一个整数通常用 >

Symbol complete. Testing for equality is usually done using ==(yes, two equal signs, because usually one equal sign is used for assignment).

There are exceptions, of course, such as the arithmetic operators of languages like Lisp and Bash, but as with any other language, this is simply a matter of mental translation. Once you understand the difference in expression, you can quickly adapt to it. A quick glance at the arithmetic operators of a programming language is usually enough to give you an idea of how arithmetic operations are done.

You also need to know how to compare and manipulate non-numeric data, such as characters and strings. This is usually done through core libraries of programming languages. For example, Python provides the split() method, while C requires the introduction of the header file string.h to provide the strtok() function.

practice

Learn about basic functions and keywords for working with basic data types, and look for core libraries that can help you with complex operations.

5. function

Class codes aren't just computer to-do lists. Often, when you write code, you want to present a computer with a set of theoretical conditions and a set of instructions for actions that the computer will take when each condition is met. Although you can do a lot with conditional statements and mathematical and logical operators for flow control, your code is much more efficient with the introduction of functions and classes because they allow you to define subroutines. For example, if your application requires a confirmation dialog box very frequently, it is much easier to write it once as an instance of a class than to rewrite the implementation each time it is needed.

You need to learn how to define classes and functions in programming languages. To be more precise, you first need to know if classes and functions are supported in the programming language. Most modern languages support functions, but classes are unique to object-oriented programming languages.

At this point, the study of "how to learn any programming language" is over, hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report