官术网_书友最值得收藏!

Development paradigms

Programming, when it first appeared, was often limited by hardware capabilities and the higher-level languages that were available at the time for simple procedural code. A program, in that paradigm, was a sequence of steps, executed from beginning to end. Some languages supported subroutines and perhaps even simple function-definition capabilities, and there were ways to, for example, loop through sections of the code so that a program could continue execution until some termination condition was reached, but it was, by and large, a collection of very brute-force, start-to-finish processes.

As the capabilities of the underlying hardware improved over time, more sophisticated capabilities started to become more readily available—formal functions as they are generally thought of now, are more powerful , or at least have a flexible loop and other flow control options, and so on. However, outside a few languages that were generally accessible only inside the halls and walls of Academia, there weren't many significant changes to that procedural approach in mainstream efforts until the 1990s, when Object-Oriented Programming first started to emerge as a significant, or even dominant paradigm.

The following is an example of a fairly simple procedural program that asks for a website URL, reads the data from it, and writes that data to a file:

#!/usr/bin/env python
"""
An example of a simple procedural program. Asks the user for a URL,
retrieves the content of that URL (http:// or https:// required),
writes it to a temp-file, and repeats until the user tells it to
stop.
"""

import os

import urllib.request

if os.name == 'posix':
tmp_dir = '/tmp/'
else:
tmp_dir = 'C:\\Temp\\'

print('Simple procedural code example')

the_url = ''
while the_url.lower() != 'x':
the_url = input(
'Please enter a URL to read, or "X" to cancel: '
)
if the_url and the_url.lower() != 'x':
page = urllib.request.urlopen(the_url)
page_data = page.read()
page.close()
local_file = ('%s%s.data' % (tmp_dir, ''.join(
[c for c in the_url if c not in ':/']
)
)).replace('https', '').replace('http', '')
with open(local_file, 'w') as out_file:
out_file.write(str(page_data))
print('Page-data written to %s' % (local_file))

print('Exiting. Thanks!')
主站蜘蛛池模板: 称多县| 疏勒县| 丰台区| 南部县| 壤塘县| 嘉义市| 会东县| 凌源市| 方正县| 青铜峡市| 遂溪县| 怀来县| 湄潭县| 安吉县| 西青区| 从江县| 隆化县| 赤壁市| 石楼县| 白朗县| 鄱阳县| 曲沃县| 都昌县| 清新县| 会宁县| 龙海市| 五指山市| 金昌市| 顺平县| 呼玛县| 黄梅县| 西林县| 丽水市| 泸溪县| 金川县| 花莲市| 嵩明县| 渝北区| 成武县| 安义县| 陈巴尔虎旗|