Path: csiph.com!news.mixmin.net!aioe.org!.POSTED!not-for-mail From: "Rod Pemberton" Newsgroups: alt.os.development Subject: Re: Smaller C Date: Sun, 13 Sep 2015 11:17:52 -0400 Organization: Aioe.org NNTP Server Lines: 177 Message-ID: References: <1debc959-af42-490a-ac12-568e59fa441a@googlegroups.com> <77032cbf-7538-42ef-a1ad-73f3ca6ee38d@googlegroups.com> <13fd448e-f885-4785-9368-04c0b75e543c@googlegroups.com> <863a5219-999a-4028-b567-a8e1e282af5d@googlegroups.com> <79c0cfce-38ec-4bcc-bd5f-a25808ffb8ea@googlegroups.com> <39da71f8-7e21-4fcb-84da-263d5c81059f@googlegroups.com> <870c24c2-224c-48e5-9955-fcbe6f67b68c@googlegroups.com> <4837e85f-886b-4db4-8b7e-6005a9f39494@googlegroups.com> <4cdea432-76e1-4493-b83d-a159449b29c3@googlegroups.com> NNTP-Posting-Host: n4wpt9zq8xR26Ttf9mo2BA.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Opera Mail/12.16 (Linux) X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com alt.os.development:8784 On Sun, 13 Sep 2015 05:53:34 -0400, Alexei A. Frounze 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?