A modern ‘Hello, World’ program needs more than just code

栏目: IT技术 · 发布时间: 4年前

内容简介:Not too long ago, a client called on me to write a program inI don’t want to admit how long it had been since I last wrote RPG other than to note it was probably before most of my readers were born. Building the program required me to remember how to use a

Not too long ago, a client called on me to write a program in RPG on an AS/400 . To quote the Great Lobachevsky , “боже мой!”

I don’t want to admit how long it had been since I last wrote RPG other than to note it was probably before most of my readers were born. Building the program required me to remember how to use a KEDIT -like editor, learn how to use the AS/400 Software Development Facility, build a testing library, edit the actual program, then compile it and figure out how to run it. 

The client’s program was relatively simple, but I didn’t want to just dive in. So I created a “Hello, World”.

A tradition with a purpose

This notion of a “Hello, World” program goes back to Brian Kernighan and Dennis M. Ritchie’s The C Programming Language (First Edition) — writing a small program in order to confirm that you understand the language and environment enough to try more complicated things. The first program most C programmers write is something like:

#include <stdio.h>

int main() {
    printf("Hello, world!\n");
    return 0;
}

Type that text into a file named ‘hello.c’, then (on any UNIX-like system) enter the commands

$ cc hello.c
$ ./a.out

and you should see the cheery result

Hello, world!

which demonstrates that you have indeed written, compiled, and executed a program in the C language.

As Kernighan and Ritchie note, building the program for C means that you’ve mastered the basic steps to start a C project.

This is the big hurdle; to leap over it you have to be able to create the program text somewhere, compile it successfully, load it, run it, and find out where your output went. With these mechanical details mastered, everything else is comparatively easy.

Okay, I’ll admit that the statement “everything else is comparatively easy” is wry humor, but it’s still true that this is a significant step in learning any programming language.

This has become a programming tradition, and like many traditions, it’s often followed without recognizing its purpose or value. So we now have an online Hello World Collection that has nearly 600 examples of “Hello, World” in languages from Ada to ZIM. Many IDEs will write a basic “Hello, World” program for you, and in many interpreted languages like Python, “Hello, World” is simply print("Hello, world!") typed into the REPL of the interpreter. 

Unfortunately, this doesn’t provide much actual insight, and to paraphrase Richard Hamming, the purpose of computing is insight, not literal strings.

What is “Hello, World” really for?

The point of K&R’s original “Hello, World” was not to see “Hello, world” on the terminal. It was instead to make sure that you have all the tools, and the basic understanding of the C language and UNIX programming environment needed in order to write a C program, and having the tools and understanding to build programs is an important first step—maybe the most important first step—in starting every project.

Often, it’s also more complicated than it first seems. A realistic project now requires not just an editor and a compiler, but an understanding of how programs are packaged, how the build environment should be structured, how you plan to maintain version control, how to actually build the program, and what the desired product of the programming project needs to deliver. So while a basic “Hello, World” program might still be only five lines of code, building the initial, ready-to-develop “Hello, World” can be much more complicated.

Starting a new project inevitably means solving a number of development problems before “everything else is comparatively easy.”

“Hello, World” for projects

Building an appropriate “Hello, World” for a project is more complicated, but the payoff is greater as well. Consider a project that is supposed to deliver—for example—a web application. As well as choosing a language, you generally need to choose your frameworks, both for the front and back ends. You need to identify how first application will be hosted and how the code will be managed and delivered.

This appropriate “Hello, World” for a project isn’t just to show you can display some output. You need to show that you’re ready to start adding features—user stories if you’re doing something like SCRUM—and pushing them out to a version of the application that can be demonstrated and tested. An appropriate “Hello, World” for a product is the most minimal version of a minimum viable product, a demonstration that with further development, you expect to be able to deliver a useful product to test and to use.

What makes an appropriate “Hello, World” project

Obviously, this appropriate “Hello, World” project is going to differ depending on the project and the environment. I teach a lot of beginners, and for any class project, I suggest they should always start with:

  • A separate project directory—for you young whippersnappers, that may be a “folder”—into which the actual code will go.
  • An initialized git repository in that folder. Yes, I do start even beginners using git. The basics are easy to learn, and I’ve seen a prodigious number of students collapse in despair because they made a small change where the results weren’t what was expected, and now they don’t remember what they changed well enough to revert to their old version.
  • A choice of the development tools they will be using—editors or IDEs, build tools, and so forth.
  • A repeatable build process more robust than typing an invocation of a compiler at a command line.
  • And only then the actual first code.

When they have that, and can edit, commit, build, and demonstrate that very minimal program, they’re prepared to build something to be happy with while avoiding a lot of mistakes that can make the actual process much less happy.

Starting a professional project “Hello, World”

It’s easy to imagine that a “Hello, World” program is just for beginners, but most every project starts with that intimidating empty directory. Often a realistic project “Hello, World” requires a suspiciously difficult and complicated process with lots of moving parts. For example, creating the very basic scaffolding for a Java program in Maven constructs ten directories and subdirectories to build a literal “Hello, World” program in Java, while the Maven build and dependency manager program downloads 1350 files into more than 550 directories.

This is hardly just a property of Java or Maven. Building a new React app with create-react-app requires 4304 directories and 28678 files .

Obviously, doing this by hand leads to madness. This complexity has forced developers to build scripts to create “Hello, World” level apps, but even these won’t be complete—you still must add source code control and possibly configure containers or continuous integration pipelines or deployment scripts.

While this is certainly immensely more complicated than the original five-line “Hello, World”, it’s still serving the same purpose: building a trivial application but ensuring that the requirements to continue development are satisfied.

Getting a good start

Any software project of any size is confronted from the beginning with some variant of the same problem: how can you contrive to master the mechanical details of starting your project, building the code, and even deploying the code so that you can concentrate on actually building code that satisfies the customer’s needs?

No matter how complicated the project will be, you can ensure that you have a good start by building a demonstration program that has the absolute minimum functionality but that exercises the whole process of building, testing, and even deploying. This is what the original “Hello, World!” was meant for, and it’s still the best start today.

Tags:beginner, bulletin , hello world , stackoverflow

以上所述就是小编给大家介绍的《A modern ‘Hello, World’ program needs more than just code》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

编程算法新手自学手册

编程算法新手自学手册

管西京 / 机械工业 / 2012-1 / 69.80元

《编程算法新手自学手册》主要内容简介:算法是指在有限步骤内求解某一问题所使用的一组定义明确的规则。程序员都会看重数据结构和算法的作用,水平越高,就越能理解算法的重要性。算法不仅是运算工具,更是程序的灵魂。《编程算法新手自学手册》循序渐进、由浅入深地详细讲解了基于C语言算法的核心技术,并通过具体实例的实现过程演练了各个知识点的具体使用流程。全书共11章,分为4篇。1~2章是基础篇,介绍算法开发所必需......一起来看看 《编程算法新手自学手册》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具