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

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!')
主站蜘蛛池模板: 沾益县| 定襄县| 高邮市| 定陶县| 田阳县| 天柱县| 广汉市| 乌兰察布市| 山阳县| 博罗县| 封丘县| 霍邱县| 溧阳市| 清新县| 岳阳市| 安吉县| 嵩明县| 宜州市| 新宾| 云南省| 吴旗县| 会理县| 郴州市| 邵东县| 军事| 惠东县| 大同县| 安顺市| 漳州市| 五莲县| 澎湖县| 龙山县| 青龙| 临江市| 筠连县| 乐清市| 加查县| 西安市| 常山县| 大兴区| 蓬莱市|