Sunday, February 27, 2022
Tuesday, March 23, 2021
The following text was extracted from my recently revised "C From A To Z" book. The tables and bulleted lists below look far better in that book.
The C language has been called: "The only portable assembly language." Which means that C is available on all computers and can be used to write anything from operating systems to device drivers, from web servers to user interfaces. Correctly written C Language programs always run significantly faster than programs written in other languages. This speed and portability has distinct advantages, both economic and application specific:
- C programs require fewer CPU cores to accomplish the same tasks compared to other languages.
- C programs manage their own memory so are not slowed by garbage collection.
- C programs are equally adept at handling strings and binary (ISO) data.
- C programs, even when run by root, can give up special permissions to run more securely.
- C programs run without the need for an enclosing environment. Ruby, for example, often requires Rails to start before the Ruby program can run. Java, for example, requires its Run Time Environment to be present to run the Java program.
- C can be used to write operating systems. Unix and Linux, for example were written in C.
- C can be used to write other languages. C++, Ruby, Python, Java and other languages are written in C.
- C can be used to interact efficiently with the outside world. Apache is a popular web server that was written in C. Sendmail, postfix and qmail are all written in C and are used for the world-wide exchange of email.
- C can be used to create databases. Posgres, mysql, and Oracle are all written in C.
- A well written C program is extremely portable and can be easily built on any system. Sometimes, a built C program can be run on other related systems (such as flavors of Linux) without the need to rebuild it for each system.
Why should you learn to program in C when there are so called modern languages available? After all, businesses practices often drive language adoption:
- Many website businesses only hire programmers who can write using the Python, Ruby, Php, or Java languages.
- Other website businesses are only interested in object-oriented languages and programmers that use them, such as C++, Python, Ruby, Php, or Java.
Yes there is! Consider the following:
- All of these modern languages are written in C: C++ is written in C. Python is written in C. Ruby is written in C. Php is written in C.
- Programs run 10 to 1000 times faster when written in C than when written in one of these other modern languages.
- C creates slimmer, more efficient code than these other languages.
- C programs start up faster than programs written in these other languages.
- C handles errors more adeptly than do these other languages, which typically use traps to handle errors.
To illustrate, we compare and contrast the speed of C to the speed of those other languages. Note that all of the following tests are available in Appendix B.
C runs faster
The problem with interpreted programs is that they run slower than compiled languages. This lethargy is because the interpreter must read and process the code a line at a time. Ruby, Python, Php, and Perl are interpreted languages. For example the php program, or a library in a web application, must interpret (run) your php code.
Compare the run time speed of these interpreted (script) programs against the run time speed for the C language program. All the programs and scripts did exactly the same thing, count up to ten-million with a loop inside another loop. In the following, the time command produces output in four fields of which we are interested in the third, the total run time:
% time php looptest.php
34.82u 0.07s 0:35.18 99.1%
% time ruby looptest.rb
45.19u 0.06s 0:45.47 99.1%
% time python looptest.py
65.24u 0.09s 1:05.97 99.2%
% time ./looptest
1.58u 0.00s 0:01.60 98.7%
Here, the compiled C program (looptest) ran in 1.6 seconds, whereas the interpreted Php program (looptest.php) ran in 35.18 seconds, which makes the C program 22 times faster. We summarize these results in the following:
Table 1: Interpreted Versus Compiled Loop Test Runtime Comparisons
Language Runtime C Faster By
C Language 0:01.60 1x
Php 0:35.18 22x
Ruby 0:45.47 28x
Python 1:05.97 41x
Another test that looked at the speed of reading and processing files showed similar results. The same file was opened, read and closed in each step of the loop:
Table 2: Interpreted Versus Compiled Read File Runtime Comparisons
Language Runtime C Faster By
C Language 0:03.90 1x
Php 2:01.04 31x
Ruby 0:37.60 10x
Python 4:57.01 76x
In the above, the file to read was /usr/dict/words, and its lines were counted 1,000 times.
And finally the comparison of results from a simple test to see if a string contains a valid integer. This test is executed in a loop 10,000,000 times:
Table 3: Interpreted Versus Compiled Integer Test Runtime Comparisons
Language Runtime C Faster By
C Language 0:02.00 1x
C++ Language 0:04.01 2x
Php 0:20.80 10x
Ruby 2:02.10 61x
The loop included a test to see if the check failed or succeeded.
Clearly the C language runs faster than these other languages by a significant amount. If you want to milk every bit of performance from your hardware, C is the obvious choice.
Consider the scalable cost of hardware versus your fixed cost of labor. Isn't it better to double the performance (code speed) on your existing hardware every six months rather than to double the cost of your hardware every six months? Such amazing efficiencies are only possible with C.
Tuesday, February 19, 2019
What would you say if I claimed that Socialism could increase the number of customers for almost any business by 14 percent? You would probably laugh. But read on and be surprised.
Most capitalists oppose socialism because of a belief that the role of government is to maximize the use of capital, while reducing the size and expense of government For example, corporations desire lower corporate taxes so that they may return greater profits to their share holders. Lower taxes means a reduced government and results in, "A lessor boot heel on the neck of every struggling businessperson."
Most businesses achieve higher profits by attracting more and more customers. One way to attract more customers is to advertise. Another way is to reduce customer cost by cutting manufacturing costs by moving manufacturing overseas, or by reducing the number of employees.
But what if there was a better way to increase the number of customers? Consider that the homeless contribute nothing to the economy and are not customers, yet draw funds from local government, and lower the quality of life for all. Consider that the poor are supported by government expense which minimizes their use as customers. Consider that the disabled contribute little to the economy, yet draw disability funds from government. And consider that when jobs are scarce, the laid off rely on unemployment payments, far less than the prior income, and of a limited duration.
A Minimum Income
One way is to streamline and thusly reduce the size of government would be to combine the homeless, the poor, the disabled, and the unemployed. A simple way to achieve this unification is with a "minimum income" or a negative income tax. A "minimum income" would be administered by the social security administration. A negative tax would be administered by the Treasury Department by way of Income Tax.
I prefer a minimum income because it is administered monthly rather than annually. In its simplest form, everyone with a social security number will receive the minimum income.
For example, a homeless man on a "minimum income" would be able to rent an apartment, pay for utilities and food, and would be in a much better position to find a job. As potentially solvent customer, he and those like him would increase spending on manufactured goods.
For example, a single mother on a "minimum income" could afford an apartment, utilities and food, and could afford to find child care so she could find a job. She and those like her would become better customers.
Note that "minimum income" is greatest when all other income is zero. Then for every $100 that all other income increases, "minimum income" would reduce by $50. This gradual reduction means that when a person gets a job his or her total income ("minimum income" plus other income) will increase to be more than "minimum income" alone. It is important that minimum income not be cut off suddenly at some level, but rather tapers off so that the poor are encouraged to find employment and better their situations.
|As other income increases, "minimum income" decreases at half the rate.|
Tuesday, December 11, 2018
A progressive sales tax would would look much different. It would be tiny or zero for low priced items, but would grow higher as the cost increased. For example the tax on a 10.00 bucket might be zero, whereas a tax on a 200,000.00 boat might be 4%. And the tax on the sale of a 5,000.000 home might be 8%.
When a medium income person buys a home it us usually for less then 250,000. When a high income person buys a home, they usually pay less then 1,500,000. When a wealthy person buys a home they usually pay 3,000,000 or more. It makes sense that, when a wealthy person buys an expensive property, they are uniquely in a position to afford a higher sales tax.
One possible formula for such a non-regressive sales tax might look like this:
If you were to buy a galvanized bucket for $9.99 you would owe no tax. If you were to buy $99.99 in groceries, you would pay three cents in tax ($100.02 total). If your were to pay 1,000.00 for a car repair, you would pay $10.00 in tax (1010.00 total). If you were to pay $10,000 to five trees removed and the stumps removed, you would pay $200.00 in tax ($10,200.00 total). If you were to pay $100,000.00 for a fully tricked out Range Rover Sport, you would pay $4,000.00 in tax ($104,000.00 total). If you were to pay $1,000,000 for a small studio condo in New York City, you would pay $80,000.00 in tax ($1,080,000.00 total).
Scaling up of the tax rate moves the bulk of the tax onto the rich. For such a non-regressive tax to work, there must be no exemptions. Although it is tempting to exempt groceries or prescription drugs, one should resist that temptation. For if groceries are exempted, then similar logic might lead to the exemption of real estate or car purchases. The choice must be to either scale the sales tax, or to apply the same tax to all and provide exemptions.
Policy will determine the rate that the tax increases. For example, instead of doubling the tax rate for each ten times the amount, perhaps triple the tax for each twenty times the amount.
Policy will also determine the amount below which no sales tax occurs. For example, you might want to benefit the poor and middle classes together. One way to do that might be to charge zero tax for all sales below one-thousand dollars.
One advantage of scaling by a formula is that formula, and starting and ending amounts, are all that are needed to find the tax. A later law might change the starting point or the ending point or the formula, but would likely change only one of the three at at time. This simplifies updates to cash registers.
The alternative is to chart the increments and rates in law. This has the disadvantage that the chart would look like a table and the entire table might have to be altered to change one amount or rate. Updates to cash registers would require a simultaneous update of them all with a new table.
Another requirement should be that sales tax never taxes a tax. For example, sales tax should only be applied to the untaxed portion of gasoline or to the untaxed portion of a hotel room.
This blog is not the end all or be all of a scaled sales tax. It is merely intended as a means to get others thinking about a non-regressive sales tax.
Monday, April 23, 2018
States have reduced access to voting by various means over the years. Such laws seek to disenfranchise based on poverty, sex, or race. Some states require photo ID before a citizen may vote. Others reduce the number of voting places in low income areas. Convicted criminals are routinely denied the right to vote.
The fundamental right to vote needs to be spelled out in the constitution once and for all to insure nobody is ever denied the right to vote.
Also, in recent history, companies, corporations, and the very wealthy have sought to influence elections in ways that reduce effectiveness of the individual vote. Although corporations are people, they are not voting citizens and so should have no right to influence elections. Also the wealthy citizen can unfairly influence an elections more than a poor citizen can. Such behavior is unfair and should be discouraged.
In support of these ends I propose a constitutional amendment something like the following:
- Section 1. No Citizen shall be denied the right to vote, except for reason of too young an age.
- Section 2. Only a Citizen may vote and only a Citizen may influence an election. Non-citizens are barred by law from influencing any election.
- Section 3. Individual wealth shall not unfairly influence any election.
- Section 4. The Congress shall have the power to enforce, by appropriate legislation, the provisions of this article.
Tuesday, September 26, 2017
|EMX Bus Approaches Eugene Station|
The Lane Transit District (LTD) opened its EMX (Emerald Express) west 11th Street extension on Sunday last the 27th of September 2017. I rode it on that opening day and found it bumpy but otherwise comfortable.
The EMX system is a Bus Rapid Transit (BRT) system. So how does EMX compare to regular buses and to light rail?
- EMX is basically a bus. Its stations are called bus stops. It has many reserved lanes in the roadway where only it, and right turning cars, may drive. It stops at signals just like all traffic and regular buses do.
- Because stops are few and far between, you can think of it as more of a Limited bus route. Riding it reminded me of the 38L on Geary Boulevard in San Francisco. A bit faster perhaps, and less crowded then the 38L. But both only stop where they cross other bus routes. In this sense, EMX is a limited stop bus route.
- Bicyclists slow down loading because bicycles most be placed on a special rack a the front of the bus, a rack that can only hold two bicycles. Contrast that to the new EMX bus. It has an internal bike rack that can hold three to six bicycles. And because bikes roll easily onto and off of the bus, their loading/unloading does not slow down the EMX bus.
- All LTD buses stick to published arrival times posted at each bus stop. The EMX bus posts those arrival times on electronic screens at each stop. When any bus, including EMX buses, runs ahead of schedule, it must pause in a bus stop and wait to get back on schedule. This is perhaps the one most annoying part of riding the LTD system. Buses that pause to fall back into schedule are frustrating. Instead, LTD signs should show when to expect the next bus in minutes. "The next bus will arrive in 7 minutes." That way, even if the bus ran ahead of schedule, the arrival would be correctly predicted without the need to pause at a bus stop. This is easy to change on EMX because they run at 10 minute intervals. So missing a bus causes little harm. This would not work on other bus lines because they run at 1/2 hour and hourly intervals where missing the bus is a crisis.
- Despite having laid special concrete in its lanes, the EMX bus ride was bumpy. All buses are bumpy because they run over road intended for other traffic. The only systems that are smooth are rail systems. Portland's light trail system, for example, is smooth. Light rail costs twice as much as BRT to build. EMX could have built half the distance and put in light rail. Would half the distance of light rail have made sense? Subways cost 10 times more than BRT to build. Would on tenth the distance of subway light rail have made sense? Probably not, because BRT gives you more distance for the buck, but BRT runs a third as fast as a subway.
- The real advantage of EMX is its frequency. During weekdays, EMX buses run one every 10 minutes. Imagine if all bus routes ran one every 10 minutes. A rider wouldn't need plan on a scheduled bus, instead the rider could simply show up at a bus stop and a bus would arrive within 10 minutes. Would buses be vastly more popular if so frequent?
- As an experiment, LTD should run an express on some busy route to see if frequency is a better draw than BRT with it level boarding and scheduled stops. By way of example, consider a 50x that could run out River Road crossing the 51, 52, and 55 lines. If it ran once each 10 minutes, and only stopped at transit transfer intersections, would it be as popular as the existing EMX line?