现代COBOL:软件包教程

You will learn and create an application-level library in COBOL. You will structure the package, implement automatic tests, deploy on GitHub and enable Continuous Integration workflow. Finally, you will publish the package in the COBOL package registry.

您将在COBOL中学习并创建应用程序级库。 您将构建软件包,实施自动测试,在GitHub上部署并启用持续集成工作流程。 最后,您将在COBOL软件包注册表中发布该软件包。

前提条件 (Preconditions)

You have learned basic principles, methods and standards of COBOL. In this tutorial we’ll use GnuCOBOL — a free COBOL compiler which implements a substantial part of the COBOL 85, COBOL 2002 and COBOL 2014 standards and X/Open COBOL, as well as many extensions included in other COBOL compilers.

您已经学习了COBOL的基本原理,方法和标准。 在本教程中,我们将使用GnuCOBOL —一个免费的COBOL编译器,该编译器实现了COBOL 85,COBOL 2002和COBOL 2014标准以及X / Open COBOL的大部分内容,以及其他COBOL编译器中包括的许多扩展。

You have Docker, a command-line virtualization tool, installed.

您已经安装了Docker (一种命令行虚拟化工具)。

You have NPM, a package manager for JavaScript programming language, installed.

您已经安装了NPM ,它是JavaScript编程语言的软件包管理器。

You have Git, an open source distributed version control client, installed.

您已经安装了Git (一个开源的分布式版本控制客户端)。

You have GitHub account for publishing of the package.

您具有用于发布软件包的GitHub帐户。

You may use any text editor you like, but I recommend Visual Studio Code (or its open-source version VSCodium) with COBOL-syntax extension bitlang.cobol installed. Package vs Library

您可以使用任何喜欢的文本编辑器,但是我建议安装Visual Studio Code (或其开放源代码VSCodium )并安装COBOL语法扩展名bitlang.cobol 。 包与库

Each programming language has standard set of functions or operators provided by default and included into installation package. In COBOL we call them Intrinsic functions. Intrinsics cover basic programming needs, but we’ve used to extend default set by own functions every time writing something smarter than ´Hello, world!´.

每种编程语言都有默认提供的标准功能集或运算符,并已包含在安装包中。 在COBOL中,我们称它们为内在函数。 内在函数满足基本的编程需求,但是每次编写比“ Hello,world!”更聪明的东西时,我们都会使用自己的函数扩展默认设置。

Gradually, custom functions form reusable COBOL libraries, Copybooks, for inclusion into other programs and services on-demand. Thanks to Version Control Systems, contributors are able to effectively cooperate and deliver the libraries to the programmers. The only problem was an integration with external source-code that might be casually written in other COBOL dialect, coding standard or approach. And package management is a solution here.

定制函数逐渐形成可重用的COBOL库,抄写本,以按需包含在其他程序和服务中。 借助版本控制系统,贡献者可以有效地合作并将库交付给程序员。 唯一的问题是与外部源代码的集成,该源代码可能是用其他COBOL方言,编码标准或方法随意编写的。 包管理是这里的解决方案。

Similar to other application-level package managers, such as Yarn for JavaScript, Maven for Java, Packagist for PHP, NuGet for C# etc., in 2020 COBOL obtained its own public package manager that standardizes the way the contributors should treat the libraries — COBOLget. The tutorial explains how to create and publish your first COBOL package the modern way.

与其他应用程序级程序包管理器类似,例如JavaScript的Yarn ,Java的Maven ,PHP的Packagist ,C#的NuGet等,COBOL在2020年获得了自己的公共程序包管理器,该程序标准化了贡献者对待库的方式— COBOLget 。 本教程说明了如何以现代方式创建和发布您的第一个COBOL软件包。

技术指标 (Specifications)

For financial applications we’ll implement banking package which exposes single iban-checksum function — an IBAN validator. The function accepts alphanumeric argument and returns numeric value 1 in case of success. The algorithm is as follows:

对于财务应用程序,我们将实现banking包,其中暴露的单iban-checksum功能-一个IBAN验证。 该函数接受字母数字参数,并在成功的情况下返回数值1 。 算法如下:

  • Check IBAN length.

    检查IBAN长度。
  • Move the first 4 characters to the end.

    将前4个字符移到末尾。

  • Replace each letter with two digits, where A = 10, B = 11, …, Z = 35.

    将每个字母替换为两位数字,其中A = 10,B = 11,…,Z = 35

  • Compute the remainder by MOD97 intrinsic function. If the remainder is 1, the checksum is valid.

    通过MOD97内在函数计算余数。 如果余数为1 ,则校验和有效。

结构化 (Structuring)

Please create new GitHub repository demo-banking and copy template of the package to your local copy of the repository. Here’s a structure of the package:

请创建新的GitHub存储库demo-banking,并将软件包的模板复制到本地存储库副本。 这是包的结构:

├── Dockerfile
├── .github
│   └── workflows
│       └── docker-image.yml
├── .gitignore
├── modules.json
├── modules-lock.json
├── README.md
├── src
│   └── banking.cbl
└── tests
    └── banking-test.cbl

For COBOLget packages Dockerfile, README.md, .gitignore and .workflows are optional, but our library follows Continuous Integration practices, where each modification of the source-code is getting tested on the repository. On each push or pull request GitHub will trigger docker-ci workflow. In its turn, Docker will download GnuCOBOL image gnucobol2.2, install COBOLget dependencies from modules-lock.json and will execute GCBLUnit tests in banking-test.cbl.

对于COBOLget包DockerfileREADME.md.gitignore.workflows是可选的,但是我们的库遵循持续集成实践,其中对源代码的每次修改都在存储库上进行测试。 在每个推送请求中,GitHub将触发docker-ci工作流。 依次,Docker将下载GnuCOBOL映像gnucobol2.2 ,从modules-lock.json安装COBOLget依赖modules-lock.json ,并将在banking-test.cbl执行GCBLUnit测试。

The file modules.json is a Manifest of the package which describes the library and its dependencies:

文件modules.json是软件包的清单 ,描述了库及其依赖项:

{
  "name": "demo-banking-FIXME",
  "description": "Demo banking package",
  "modules": [
    "src/banking.cbl"
  ],
  "dialect": "gnucobol",
  "licenses": [
    "MIT"
  ],
  "authors": [
    "FIXME"
  ],
  "dependencies": {},
  "dependencies-debug": {
    "gcblunit": "*"
  }
}

The properties are speaking enough and similar to other package managers. Our package does not use any dependencies, but requires gcblunit package at any version (by default, the latest available) for development and debugging purposes. Property modules must contain COBOL modules (programs and functions) for inclusion as a Copybook. Full schema of the Manifest you may find on https://cobolget.com/schema.json.

这些属性足以说明问题,并且与其他包管理器类似。 我们的软件包不使用任何依赖关系,但需要任何版本的gcblunit软件包(默认情况下为最新版本)才能进行开发和调试。 属性modules必须包含COBOL模块(程序和函数)才能包含在Copybook中。 您可以在https://cobolget.com/schema.json上找到清单的完整架构。

Let’s install cobolget command-line tool and validate our package:

让我们安装cobolget命令行工具并验证我们的软件包:

$ npm install -g cobolget
$ cobolget validate
An error occurred: Error: "demo-banking-FIXME" does not match to ^[a-z0-9\-]+$

Oops! Please replace FIXME with your GitHub username in README.md, as well as in the Manifest in lower-case, making the package valid and unique in the COBOLget registry. Don’t forget to replace FIXME in the command below as well:

糟糕! 请在README.md以及小写的清单中用您的GitHub用户名替换FIXME ,以使包在COBOLget注册表中有效且唯一。 不要忘记在下面的命令中也替换FIXME

$ cobolget validate
Manifest modules.json is valid.
$ cobolget list demo-banking-FIXME
No matching results.

Well done! The structure of the package is finished. We’ll test our library in the next step.

做得好! 包装的结构已完成。 我们将在下一步中测试我们的库。

测试中 (Testing)

The file banking-test.cbl has 8 GCBLUnit assertions that expect “1” returned by iban-checksum function. Let’s execute docker-ci workflow locally, an one-liner

文件banking-test.cbl具有8个GCBLUnit断言,这些断言期望iban-checksum函数返回“ 1” 。 让我们在本地执行docker-ci工作流

$ docker build --tag package .

As you can see, creation of the Docker image fails on testing phase.

如您所见,在测试阶段创建Docker映像失败。

....FFFF

Time: 00:00:00
There was 0000000004 failure(s):
F banking-test #05 assert-equals    1 <> 0                               
F banking-test #06 assert-equals    1 <> 0                               
F banking-test #07 assert-equals    1 <> 0                               
F banking-test #08 assert-equals    1 <> 0

FAILURES!
Tests: 0000000001, Skipped: 0000000000
Assertions: 0000000008, Failures: 0000000004, Exceptions: 0000000000
The command '/bin/sh -c cobc -x -debug modules/gcblunit/gcblunit.cbl tests/* --job='banking-test'' returned a non-zero code: 1

The last 4 of 8 assertions returned “0” instead of expected “1”. Definitely, it’s a false negative result because these numbers have been carefully copied from Wikipedia. :) You may remove inner spaces and try again, but I suggest you to improve iban-checksum function instead. Spaces are generally acceptable in IBAN and must pass the validation. The best implementation will be included into core COBOLget package under your name. Nevertheless, you may commit and push the package on GitHub and proceed to the next step.

8个断言中的最后4个返回“ 0”,而不是预期的“ 1” 。 当然,这是一个假阴性结果,因为这些数字已从Wikipedia中精心复制。 :)您可以删除内部空间,然后再试一次,但是我建议您改为改进iban-checksum函数。 空格在IBAN中通常是可接受的,并且必须通过验证。 最佳实现将以您的名字包含在核心 COBOLget软件包中。 不过,您可以在GitHub上提交并推送该软件包,然后继续下一步。

出版 (Publishing)

Please “release” your package on GitHub by attaching a version tag e.g. 1.2.3 to the commit. COBOLget implements SemVer versioning standard, any other tags will be skipped during the import. Now you can import your package into COBOLget Registry by using index command, from the command-line or on the website.

请通过在提交上附加一个版本标记(例如1.2.3在GitHub上“释放”您的软件包。 COBOLget实现了SemVer版本控制标准,在导入过程中将跳过任何其他标签。 现在,您可以使用index命令从命令行或在网站上将软件包导入COBOLget Registry

$ cobolget index -h
Usage: index [options] <name|url>

Import or update the package in the registry

Options:
  -t, --token <token> Repository token for private package
  -o, --organization <organization> Organization name for private package
  -h, --help output usage information

Newborn packages we index by URL of the repository. Further releases we can index by the name.

我们通过存储库的URL为新生儿包建立索引。 进一步的发行版本我们可以按名称索引。

$ cobolget index https://github.com/FIXME/demo-banking
Package 'demo-banking-FIXME' has been indexed in the registry.

Your first COBOL package is published on cobolget.com and ready for integration into applications and microservices.

您的第一个COBOL软件包已发布在cobolget.com上,可以集成到应用程序和微服务中

结论 (Conclusion)

You have created and successfully published your application-level COBOL library in COBOLget format by using Git, Docker, Unit-Testing and Continuous Integration practices. 60-years old COBOL fits modern software engineering.

您已经使用Git,Docker,单元测试和持续集成实践以COBOLget格式创建并成功发布了应用程序级COBOL库。 已有60年历史的COBOL适合现代软件工程。

Are you Wikipedia editor? Please help publish missing article from the sandbox.

您是维基百科的编辑吗? 请帮助发布失踪文章沙箱

翻译自: https://habr.com/en/post/515112/

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
vscode 最新插件集合,更新到20180815,共4part,需要全部下载后解压,包含一下插件: batisteo.vscode-django-0.17.0 bibhasdn.django-html-1.2.0 bibhasdn.django-snippets-1.1.0 bitlang.cobol-3.4.2 christian-kohler.npm-intellisense-1.3.0 christian-kohler.path-intellisense-1.4.2 chrmarti.regex-0.2.0 coenraads.bracket-pair-colorizer-1.0.59 daltonjorge.scala-0.0.5 danields761.dracula-theme-from-intellij-pythoned-0.1.4 davidanson.vscode-markdownlint-0.19.0 dbaeumer.vscode-eslint-1.4.12 donjayamanne.jupyter-1.1.4 donjayamanne.python-extension-pack-1.4.0 dotjoshjohnson.xml-2.3.1 eg2.vscode-npm-script-0.3.5 eriklynd.json-tools-1.0.2 fisheva.eva-theme-0.4.0 formulahendry.code-runner-0.9.4 formulahendry.terminal-0.0.10 fwcd.kotlin-0.1.8 gerane.theme-druid-0.0.2 grapecity.gc-excelviewer-2.1.25 humao.rest-client-0.19.1 humy2833.ftp-simple-0.6.7 ikuyadeu.r-0.6.0 Ikuyadeu.r-lsp-0.0.7 itryapitsin.scala-0.1.7 itryapitsin.scalasnippets-0.1.7 jasonnutter.search-node-modules-1.3.0 jithurjacob.nbpreviewer-1.0.0 josephtbradley.hive-sql-0.0.2 julialang.language-julia-0.10.3 kalitaalexey.vscode-rust-0.4.2 kondratiev.sshextension-0.3.0 luqimin.forgive-green-0.2.1 magicstack.magicpython-1.0.12 mohsen1.prettify-json-0.0.3 mooman219.rust-assist-0.2.2 ms-ceintl.vscode-language-pack-zh-hans-1.25.3 ms-ceintl.vscode-language-pack-zh-hans-1.26.3 ms-kubernetes-tools.vscode-kubernetes-tools-0.1.12 ms-python.anaconda-extension-pack-1.0.0 ms-python.python-2018.7.1 ms-toolsai.vscode-ai-0.1.9 ms-vscode.cpptools-0.17.7 ms-vscode.go-0.6.86 ms-vscode.go-0.6.87 ms-vsliveshare.vsliveshare-0.3.535 mtxr.sqltools-0.15.0 peterjausovec.vscode-docker-0.1.0 pkief.material-icon-theme-3.5.2 qub.qub-xml-vscode-1.2.8 redhat.java-0.29.0 redhat.vscode-yaml-0.0.14 rogalmic.bash-debug-0.2.1 rust-lang.rust-0.4.9 scala-lang.scala-0.1.2 sensourceinc.vscode-sql-beautify-0.0.4 truman.autocomplate-shell-0.1.1 vahidk.tensorflow-snippets-0.3.3 visualstudioexptteam.vscodeintellicode-1.0.3 vscjava.vscode-java-debug-0.11.0 vscjava.vscode-java-pack-0.3.0 vscjava.vscode-java-test-0.8.0 vscjava.vscode-maven-0.10.0 waderyan.nodejs-extension-pack-0.1.9 wholroyd.jinja-0.0.8 xabikos.javascriptsnippets-1.7.0 yzhang.markdown-all-in-one-1.6.0 ZakCodes.rust-snippets-0.0.1 zhuangtongfa.material-theme-2.15.4

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值