Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > alt.os.development > #8784

Re: Smaller C

From "Rod Pemberton" <boo@fasdfrewar.cdm>
Newsgroups alt.os.development
Subject Re: Smaller C
Date 2015-09-13 11:17 -0400
Organization Aioe.org NNTP Server
Message-ID <op.x4wp32moyfako5@localhost> (permalink)
References (15 earlier) <op.x4tlsdpnyfako5@localhost> <mt109k$kje$1@dont-email.me> <op.x4v45jxsyfako5@localhost> <mt3fgt$jot$1@dont-email.me> <4cdea432-76e1-4493-b83d-a159449b29c3@googlegroups.com>

Show all headers | View raw


On Sun, 13 Sep 2015 05:53:34 -0400, Alexei A. Frounze <alexfrunews@gmail.com> wrote:

> On Sunday, September 13, 2015 at 2:28:47 AM UTC-7, James Harris wrote:
> ...
> [James wrote in reponse to Rod]

>> Consider
>>
>>   file1.c
>>     int aa;
>>     static int bb;
>>     void ff(....) { .... }
>>     static void gg(....) { .... }
>>
>>   file2.c
>>     int aa; <== error
>>     static int bb; <== no error
>>     void ff(....) { .... } <== error
>>     static void gg(....) { .... } <== no error
>>
>> Untested but AIUI the names bb and gg will be local to the files they
>> are defined in. They can never conflict with names in other files, no
>> matter how large the project gets or how many programmers are working on
>> it. I find that's particularly useful for functions. If I write a helper
>> function in one file I can declare it static to make sure its name
>> doesn't leak out and it cannot be referenced from other files.
>
> Rod has mentioned a few style guides and they touch this topic:
>
> 1. Avoid names that might conflict with various standard library
> names.

Compilers warn of this.

> Some systems will include more library code than you want.
...

> Also, your program may be extended someday.

Yes, by you.  Typically, not by others.

> 2. Name space pollution: Minimize the number of global symbols
> in the application.

This is good for programs broken into multiple files and
managed by groups of people.  This is not a concern for
single file applications or programs written and maintained
by a singular author in private.

> One of the benefits is the lower probability
> that any conflicts will arise with system-defined functions.

This is an exceptionally low probability as is.  Most programmers
know the names of all or nearly all system functions or know the
types of names to avoid.

> I wonder if Rod writes code without any global and static
> variables

I write C code without any static variables, except once.
I write C code with globals and pass variables as is needed
by the code.  If the data or variable is being passed among
many procedures and/or speed is an issue, it makes more sense
to use globals than it does to keep passing the variables
around slowly or repeatedly.  If speed is not a concern and/or
there is minimal passing, then locals are used.  If it makes
no sense to pass the data because it is simply too large an
amount of data to pass, then it'll be global too.  I also
prefer to have all file pointers be global so they can be
used wherever they are needed.  All except a few of my personal
programs are single file.  I.e., no linking with other files
except the C libraries.  Only a few are comprised of multiple
files.  I don't intentionally keep the name spaces of the
variables separate.  This generally happens by through
happenstance and through use of locals.  Of course, coding
in a professional environment such as for work likely has
a set of rules for naming, use of qualifiers, and all sorts
of other things, like the MISRA and Safer C rules I provided
links for, to which I simply don't have to comply with for
my personal code.

> or he simply chooses what good advice to adopt and what
> to ignore.

I adopt good advice.  That's why I only adopted one practice
 from the C style guides.  Unfortunately, most people's IQs are
below mine, so I don't generally get much good advice from
people which is good for me.  I get their best advice, for
their IQ, but it's just not good enough for mine.  And, I
definately chose to avoid bad advice because it's a quick way
to mess up everything.  One of the things I learned many, many
years ago is that people can only accept advice that is just
slighly more intelligent than what they came up with on their
own.  They simply can't comprehend anything more intelligent
than that.  So, they don't recognize it's value.

> The same applies to const, especially in C++, where things are
> an order of magnitude more complex. Again, I don't know what kind
> of projects Rod has worked on, but I do from time to time have
> to join an existing unfamiliar and large project with a lot of
> code and these consts serve not only as road blocks on my way
> of modifying anything I feel like to, but also as a hint.

Well, I've never coded on a public C project or used C in a
work environment.  I have worked on public C code in private
which is how I know 'const' and 'static' are plastered throughout
some of them.

I learned C in the early 1990's, self-taught, from a number of
C books I purchased, but primarily Harbison & Steele's book,
which was the leading C reference at the time.  I already had
experience in Pascal and Fortran (high school and university),
and, before that, BASIC and 6502 assembly (self-taught).  I
wrote my first computer program using Logo in 1981 at a night
class.

The largest project I worked on was a private code base of 5MLoc
in a PL/I variant (Stratus PL/1) for a brokerage.  We had four T1s
feeding quotes and trade data to a real-time, online transaction
procesing application (OLTP) and in-memory database which had
transaction protection for proprietary trading in stocks which
ran on two fault-tolerant Stratus Continuum 600s.  I maintained
the code, complied with NYSE and Nasdaq regulatory changes,
implemented applications from scratch to create federal regulatory
reports, maintained corporate financial reports, and modified
one of their line handlers to handle updated Nasdaq protocols,
wrote a variety of utilities, etc.  That was over a decade ago.

I planned on becoming an electrical engineer (EE) since I had
a fanatical interest in electronics since middle school.  I
learned how to read schematics on my own.  I bought an
oscilloscope and taught myself how to use it.  I knew probably
about as much about electronics as a someone with a masters in
EE, if not a PhD, coming out of high school.  But, for reasons
still unknown to me, my life perspective and interests changed
rapidly and unexpectedly.  I completely lost all interest in
electronics immediately after graduating from high school.  It
was like a light switch turned off for which I couldn't turn
back on.  Then, somewhat lost as to what I wanted to do or
become, I bounced around universities and colleges.  I decided
I wanted to try computer programming, but was told the market
was non-existant here, which it was at the time.  It improved
much just a few years later, but it's still not a great place
to be a programmer.  So, I became an electronic technician for
a while working with analog audio and DSPs, for which I was
overskilled and educated, but loved the extremely underpaid
work.  Next, I caught a lucky break and moved into computer
programming, which became another job I loved and after a
bit it became well-paying.

One of the other guys in my high-school class who was roughly
of similar intellect has a PhD in chemistry and is now a
university professor.  Back then, I was very strong in math,
physics, chemistry, and electronics.  Programming was just a
hobby.  However, I had no interest in chemistry, and wasn't
all that interested in being a physicist.  Today, I'm strong
in programming, and have interests in finance, economics, the
discoveries of physics and genetics, and many other things not
so academic or intellectual or mathematical.  I still have a
trivial interest in electronics, and an in-depth understanding
of electronics well beyond what any non-EE should ...  Of course,
my math skills are far too rusty to solve any of those types of
problems today, except for the most trivial.  I have well above
average spatial-relations.  I once had a perfect score on the
spatial-relations portion of a standardized test in high school
for which no one had ever scored above 47%.  It's like I have
AutoCad in my head, but without dimensions.  I used to solve
20 geometry problems in 2 minutes and could solve about 60
physics problems in an hour because of this ability.

So, that's who I am.  Who are you?


Rod Pemberton

-- 
Just how many texting and calendar apps does humanity need?

Back to alt.os.development | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Smaller C "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-07-11 20:39 -0700
  Re: Smaller C "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-07-12 04:24 -0400
    Re: Smaller C "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-07-12 03:17 -0700
      Re: Smaller C "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-07-13 03:28 -0400
    Re: Smaller C "James Harris" <james.harris.1@gmail.com> - 2015-07-12 19:12 +0100
      Re: Smaller C "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-07-12 17:09 -0700
      Re: Smaller C "James Harris" <james.harris.1@gmail.com> - 2015-07-13 11:10 +0100
        Re: Smaller C "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-07-13 23:13 -0400
          Re: Smaller C "James Harris" <james.harris.1@gmail.com> - 2015-07-14 09:08 +0100
            Re: Smaller C "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-07-15 02:23 -0400
  Re: Smaller C "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-08-15 02:12 -0700
    Re: Smaller C "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-09-06 15:54 -0700
      Re: Smaller C "Benjamin David Lunt" <zfysz@fysnet.net> - 2015-09-07 12:19 -0700
        Re: Smaller C "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-09-07 13:30 -0700
          Re: Smaller C "Benjamin David Lunt" <zfysz@fysnet.net> - 2015-09-09 19:38 -0700
            Re: Smaller C "Benjamin David Lunt" <zfysz@fysnet.net> - 2015-09-09 19:49 -0700
            Re: Smaller C "Benjamin David Lunt" <zfysz@fysnet.net> - 2015-09-09 20:58 -0700
            Re: Smaller C "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-09-10 01:45 -0700
              Re: Smaller C "Benjamin David Lunt" <zfysz@fysnet.net> - 2015-09-10 10:45 -0700
                Re: Smaller C "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-09-10 23:20 -0700
                Re: Smaller C "wolfgang kern" <nowhere@never.at> - 2015-09-11 09:26 +0200
                Re: Smaller C "wolfgang kern" <nowhere@never.at> - 2015-09-11 09:50 +0200
                Re: Smaller C "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-09-11 00:58 -0700
                Re: Smaller C "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-09-11 17:38 -0400
                Re: Smaller C "James Harris" <james.harris.1@gmail.com> - 2015-09-11 23:39 +0100
                Re: Smaller C "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-09-11 19:39 -0400
                Re: Smaller C "James Harris" <james.harris.1@gmail.com> - 2015-09-12 11:22 +0100
                Re: Smaller C "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-09-12 02:21 -0700
                Re: Smaller C "wolfgang kern" <nowhere@never.at> - 2015-09-12 21:53 +0200
                Re: Smaller C "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-09-13 03:37 -0400
                Re: Smaller C "James Harris" <james.harris.1@gmail.com> - 2015-09-13 09:49 +0100
                Re: Smaller C "wolfgang kern" <nowhere@never.at> - 2015-09-13 12:58 +0200
                Re: Smaller C "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-09-13 07:32 -0400
                Re: Smaller C "James Harris" <james.harris.1@gmail.com> - 2015-09-13 19:05 +0100
                Re: Smaller C "James Harris" <james.harris.1@gmail.com> - 2015-09-14 13:19 +0100
                Re: Smaller C "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-09-15 00:01 -0400
                Re: Smaller C "James Harris" <james.harris.1@gmail.com> - 2015-09-18 14:48 +0100
                Re: Smaller C "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-09-26 16:23 -0400
                Re: Smaller C James Harris <james.harris.1@gmail.com> - 2015-09-27 00:23 +0100
                Re: Smaller C "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-09-26 16:37 -0700
                Re: Smaller C "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-09-27 10:17 -0400
                Re: Smaller C "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-09-27 10:24 -0400
                Re: Smaller C "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-09-27 10:46 -0400
                Re: Smaller C James Harris <james.harris.1@gmail.com> - 2016-01-16 16:14 +0000
                Re: Smaller C Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-01-23 13:20 -0500
                Re: Smaller C James Harris <james.harris.1@gmail.com> - 2016-01-27 13:52 +0000
                Re: Smaller C "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-09-27 10:28 -0400
                Re: Smaller C James Harris <james.harris.1@gmail.com> - 2016-01-16 16:31 +0000
                Re: Smaller C Rod Pemberton <NoHaveNotOne@bcczxcfre.cmm> - 2016-01-23 13:20 -0500
                Re: Smaller C "James Harris" <james.harris.1@gmail.com> - 2015-09-18 16:21 +0100
                Re: Smaller C "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-09-20 17:25 -0700
                Re: Smaller C "wolfgang kern" <nowhere@never.at> - 2015-09-13 12:43 +0200
                Re: Smaller C "James Harris" <james.harris.1@gmail.com> - 2015-09-13 09:21 +0100
                Re: Smaller C "wolfgang kern" <nowhere@never.at> - 2015-09-13 13:02 +0200
                Re: Smaller C "James Harris" <james.harris.1@gmail.com> - 2015-09-13 19:09 +0100
                Re: Smaller C "Benjamin David Lunt" <zfysz@fysnet.net> - 2015-09-11 13:32 -0700
                Re: Smaller C "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-09-11 18:51 -0400
                Re: Smaller C "Benjamin David Lunt" <zfysz@fysnet.net> - 2015-09-11 18:16 -0700
                Re: Smaller C "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-09-12 02:36 -0700
                Re: Smaller C "James Harris" <james.harris.1@gmail.com> - 2015-09-12 11:56 +0100
                Re: Smaller C "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-09-13 03:45 -0400
                Re: Smaller C "James Harris" <james.harris.1@gmail.com> - 2015-09-13 10:28 +0100
                Re: Smaller C "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-09-13 02:53 -0700
                Re: Smaller C "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-09-13 11:17 -0400
                Re: Smaller C "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-09-13 16:54 -0700
                Re: Smaller C "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-09-13 21:39 -0400
                Re: Smaller C "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-09-13 20:31 -0700
                Re: Smaller C "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-09-13 09:03 -0400
                Re: Smaller C "James Harris" <james.harris.1@gmail.com> - 2015-09-13 19:48 +0100
                Re: Smaller C "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-09-13 21:33 -0400
                Re: Smaller C "James Harris" <james.harris.1@gmail.com> - 2015-09-14 23:17 +0100
                Re: Smaller C "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-09-20 17:37 -0400
                Re: Smaller C "James Harris" <james.harris.1@gmail.com> - 2015-09-20 23:46 +0100
  Re: Smaller C "Benjamin David Lunt" <zfysz@fysnet.net> - 2015-09-11 21:37 -0700
    Re: Smaller C "Benjamin David Lunt" <zfysz@fysnet.net> - 2015-09-11 22:29 -0700
      Re: Smaller C "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-09-12 03:25 -0700
        Re: Smaller C "Benjamin David Lunt" <zfysz@fysnet.net> - 2015-09-12 11:18 -0700
          Re: Smaller C "Benjamin David Lunt" <zfysz@fysnet.net> - 2015-09-12 11:39 -0700
          Re: Smaller C "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-09-13 03:47 -0400
            Re: Smaller C "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-09-13 11:31 -0400
          Re: Smaller C "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-09-13 02:00 -0700
            Re: Smaller C "Rod Pemberton" <boo@fasdfrewar.cdm> - 2015-09-13 11:31 -0400
            Re: Smaller C "Benjamin David Lunt" <zfysz@fysnet.net> - 2015-09-13 09:15 -0700
    Re: Smaller C "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-09-12 02:45 -0700
      Re: Smaller C "Benjamin David Lunt" <zfysz@fysnet.net> - 2015-09-12 10:55 -0700
  Re: Smaller C "Benjamin David Lunt" <zfysz@fysnet.net> - 2015-09-15 19:23 -0700
    Re: Smaller C "Alexei A. Frounze" <alexfrunews@gmail.com> - 2015-09-16 03:03 -0700
      Re: Smaller C "Benjamin David Lunt" <zfysz@fysnet.net> - 2015-09-16 10:17 -0700

csiph-web