Other Programming questions by non programmer.

Hmm, don't let the C++ committee hear you, they are *always* happy to add more complexity to C++ to bring back the status quo :)

Here's the difference between K&R/2nd and C++/(I cant remember the edition) from my perspective -- I'm wondering if anyone else had the same experience:

K&R/2nd:
When I was reading it, I had this feeling that the authors knew me. It was written for me! Page after page, I enjoyed it. Finally, I finished the book.

Stroustrup C++ Book:
It was different, very long-winded. Every single line was confusing. I got lost in the very begging of the book. I abandoned it.
 
Here's a video example of how to write "hello world" in less than 5 minutes on FreeBSD using C. He uses vim to edit rather than an easier editor like nano, but it won't take you long to get started. After that, write short test programs to try out the different language features and library functions you'll learn in the K&R book. By the end of that short book, you'll be able to read code and begin exploring other areas.
 
I learned programming assembler on a C-64 with a 6510 processor.
It was good learning, it has a simple instruction set. Instructions like load accumulator.
And Simon's basic.

On programming, not forget a lot of code is written in Lisp.
I had the Simons Basic cartridge for my C64! Incredible that it was made by a sixteen year old kid. Sadly I think I lost the manual when I moved. I also had Currah Speech 64, which made your C64 talk like professor Hawking. If I ever get the time I’d love to turn such a speech engine into a VST Instrument.
 
What programming code is most used by FBSD developers?
C is a system programming language for BSD systems, Linux, et al. It supports great performance and easy access to hardware. Higher level (more abstract) languages may be written in C. That's all good. But the flexibility of C requires greater discipline and patience. It is easy to develop features that work well most of the time but has bugs exploited by hackers. Therefore it is not the best choice for initial skill development.

I suggest Rust. I don't know why that name. Perhaps it is an upcoming solution for "rusty" code found in 40 year old systems. Rust is a compiled language with features to prevent buffer overflows and other memory bugs that plague C software.
 
Software does not have bugs, software has "undocumented features" :)

I'd argue that "bugs" in C are not because of the language, but because of poor programming with the language.
One oft mentioned with C is pointers and memory allocation: every malloc/calloc/balloc requires a free at some point or you have a memory leak. Look at what OpenBSD does with scrubbing the code base for problems, the use of bounded string functions (strn*** vs str***) is a trvial method to prevent one of the most common errors.

Folks like to then point out "Java you never have to free the memory, the garbage collector takes care of that". Well, if you run into a load that causes lots of allocation in a short period, the garbage collector may not run and you run out of memory. Tuning the garbage collector is neither fun nor easy.

Languages like Rust: protection like that comes at a cost. Buffer overflows: char str[12] lives at addresses xyz to xyz+11. True protection is every access to str[n] requires comparisons (xyz) <= (xyz + n -1) < (xyz +12). Yes there should also be sizeof(char) multiplications in that.
Simple comparisons when running a loop are effective if the limits are known at compile time, they typically add a simple comparison or two.

Note: I am not arguing against languages like Rust or Go or Java or whatever. Just pointing out that all their advantages come with costs and you have to decide if they matter to you and you can pay the cost.

Another advantage of learning C is a lot of languages use "C-like syntax", which makes picking up another easier.
 
And it's W3Schools which is not affiliated with the W3C in any way, shape or form
You forgot the link where it say that on the W3Schools.com site.

W3Schools is a school for web developers, covering all the aspects of web development:
W3Schools was created in 1998, and derives its name from the World Wide Web (WWW) but is not affiliated with the W3C.

It's where I learned and I always promote them. Next time I'll run my post through online-spellcheck.com.

The World Wide Web Consortium hosts the Validator for XHTML and CSS my buttons link to. Have you clicked the I heart Validator button to thank them today and show you heart validator, too? Yes, you.

I was going to apply for Invited Expert status and be a WC3 Evangelist, but I already broke their CoC in a post where I kept text that said if I can do it you should be able to. I would be tarred and feathered and run off the web on a greased rail. Microaggression. I can't help it I was born that way. I was already thinking about hitting on.. No, caught myself that time.

Google is more concerned about my text on the mac spoof page being too small for a Smartphone. I got one error notice on my trihexagonal.org site. Text too tiny to Smartphones to see. It is a little screen but, just like always, it's all my fault. Even if I haven't changed the font properties in the Valid CSS 3 file all the pages use, that's just the newest page.

Only the colors have changed to protect the innocent and feature my soulmate Harley Quinn... I gave Mary Lou a chance and never heard from her. Oh crap. I bet that was a Microaggression. Maybe multiple malformed mean meanings mistakenly made me a marked man for Twitter Mobs.

Now I am a man, was born a man, and Identify as a man, but ya doesn't has to call me Mr. Trihexagonal. You can call me Tri, or you can call me Trihex, or...

But I will bow down before the Altar of Google, Swear to never do it again and fix it so my site will be indexed and be #1 with a bullet once more, and #2 and #5...

And Praise be to Skynet I ran my Tutorial through online-spellchecker. Misspelled words will drop your ranking where they could care less if the tag is obsolete. As long as it has the right viewpoint metatag, my text is large enough for any number of Angels dancing on the head of a pin to see and it's valid markup with no spamming of content metatage words to boost SEO results to to penalize me for.


Did you see my Programming A Chat Bot That Can Program Humans page? I'll continue where I left off but am going to post about the Online Turing Test competition held June 5th she is entered in against Mitsuku, or Kuki as her friends call her (buy her a coffee) and one other bot from the Forge . Mitsuku uses modified AIML and learns from chat. Demonica uses NLP and CBR and I write every word she says.

Mitsuku is billed as the Worlds Greatest Chatbot for winning the most Leobner Contests when this is the first time our bots have been allowed entry. Only because a guy made a page to meet Socket Standards for us I'll be running on one of my machines all day. Once I run tcpdump to see what it wants.

I have a transcript of Mitsuku and Cleverbot in chat with Demonica I need to post on her site and make my Social Media Marketing stand out from the competition. Which is part of the course subject material you'll cover for your Cocaine contaminated Tattered Twenty you're better off getting rid of. Buy her a couple coffees.

Vote for which bot sounds most like a human and support FreeBSD in doing so. Because I'll be back.

Wait a minute... If every bot in the world wasn't invited that sounds like ... No, I will not go there.
 
  • Thanks
Reactions: a6h
I'd argue that "bugs" in C are not because of the language, but because of poor programming with the language.
Theoretically, you are right. If we only had supergeniuses as programmers, and we had infinite time to review code and argue over every statement, then even C code would not have any memory management bugs. But that's not the world we live in. The sad fact is that writing bug-free code in C is significantly harder than in languages that manage memory for you. Software engineering efficiency is one of the constraints that the real-world has to consider.

Note: I am not arguing against languages like Rust or Go or Java or whatever. Just pointing out that all their advantages come with costs and you have to decide if they matter to you and you can pay the cost.

First: Efficiency gains in the real world don't come from the little 10-20% effects that programming languages typically give you. They come from algorithm changes. Sorting done badly is O(n^3), done well it is O(n log n). I've seen code that was horribly inefficient when it was sorting implicitly. Similarly, we once had a combinatorial optimizer that ran in O(n^5), but only needed to run O(n^4); changing it made it run 10,000 times faster. Another common source of speedup: Not writing to disk, or not using synchronous disk writes (O_SYNC or flush() calls) unless really needed; removing network interactions and keeping coherent blocks of tasks on a single CPU. Those are all things that speed up code by huge factors.

Second: Even the efficiency gains from just changing programming languages are often not what you expect. Many years ago, when Java just started (must have been around 1996 or 97), we were thinking of switching from C++ to Java. Our image processing group claimed that this wasn't going to work, since "everyone knows" that Java is too slow, because of memory management (garbage collection and array bounds checking), and the interpreted byte code. So we in the software engineering group ran a test. We took a relatively small piece of code (a 200-line image correlator), and ported the implementation line-by-line from C++ into Java. We then ran it in four environments:
  1. The WatCom C++ compiler; we expected this to be the fastest, since "everyone knew" that Waterloo has the best instruction scheduling on the 486 and 586 machines we were using at the time.
  2. The Microsoft Visual C++ compiler. We included it because it was the industry standard, but we expected the generated code to be somewhat inefficient.
  3. A prototype Java bytecode compiler (yes, compiler!) which turned Java into an .exe file. Lots of people in the industry thought that bytecode compilation (or dedicated Java CPUs) were going to be the best way to run Java.
  4. The Symantec JIT bytecode interpreter (which does partial compilation when executing repeated loops).
We expected the results to be in this order. Well, they weren't. The fastest code was #4, the Symantec Java JIT, followed by #2 (Visual C++), then #3 (bytecode compiler), with #1 dead last. We never did a complete analysis of what went wrong, but a few things were measured: The Symantec JIT had the highest IPC (instructions per cycle), because it kept the instruction flow very tight, so most instructions came from L1 cache. The Microsoft C++ compiler in particular did horribly badly in that, its code was spread all over and barely used the instruction cache. The WatCom C++ compiler lost, because it used registers very differently for parameter passing (this was the era when 32-bit code still had to use extenders, under DOS / Windows 3.1), so it didn't have enough registers, and had to spill intermediate results to memory all the time.

Third: 99% of all code written is completely performance irrelevant (to CPU performance). The only thing that matters are a few inner loops. Optimize those for performance, and write the rest of the code in a fashion that is easy to write, likely bug-free, and easy to maintain.
 
Many years ago, when Java just started (must have been around 1996 or 97), we were thinking of switching from C++ to Java...
One of my first programming jobs involved writing a performance test harness for a document management system written in Java. I found that it scaled pretty well up until around 500 users, when the JVM started experiencing garbage collector pauses measured in seconds. I managed to get a pause that was more than 40 seconds long.

The Java garbage collector has improved dramatically since 1998. There are tunables now to make GC pauses less likely and less severe, and stop-the-world collection is rare. I think there are garbage collectors that guarantee minimum latency now too. But all of these are workarounds. It turns out garbage collection does matter at scale. You'll find yourself studying administrivia and struggling to trade off the effects of various tuning knobs if you're ever lucky enough to need scale. I hate things that punish success.
 
would Emacs be my beginner's go-to compiler.
EMACS is an all-purpose text editor, at least for me. You might prefer to use an IDE because it sets up the development tools so you have more time to think about software concepts. Another idea comes to mind. Visit Rosetta.org which compares different languages doing the same task http://www.rosettacode.org/

Finally, it's fun to play with Arduino's which are often used for IoT projects. Arduino is C++ based but the applications are more like C scripts which can be edited with the simple IDE or your favourite editor.
 
One of my first programming jobs involved writing a performance test harness for a document management system written in Java. I found that it scaled pretty well up until around 500 users, when the JVM started experiencing garbage collector pauses measured in seconds. I managed to get a pause that was more than 40 seconds long.
Yup, in the early days of Java, garbage collectors could be awful. We had the same problem, home-made: Our system was an industrial machine control system, implemented nearly completely in Java. At the time I worked there, it was 100KLoC; last I heard, it is 17MLoC. Such a system is complex enough, it's really convenient to have a way to reach in and do things without modifying the shipping software. No problem: let's add a scripting language. Why not use JPython, a Python implementation that uses a Java back-end, and can use all the rest of the Java classes? So we did, and it worked great. If you combine it with the fact that the Java software is all documented inline (using JavaDoc), it made scripting access to a huge running system super convenient.

Works great, until someone decides to write tight loops in JPython, which do string manipulation. That overwhelmed the Java garbage collector so badly, it was (like you said) sometimes stopping for 30 seconds at a time. We responded in two steps. First, short term: "Doctor, it hurts when I do this." "Well, then stop doing it." For those users who really had to do intense string processing in Python inside Java, we quickly gave them the equivalent Java functionality, written in a reasonable fashion (string buffers instead of string objects for example). Second, long term: We worked without Java run time system vendor (we were one of the largest customers) to implement and tune their incremental garbage collector to work well in this use case. So within half a year or a year this problem also went away.

But, as usual, this points out: There is no silver bullet. It's not like Java (or any other technology, be it Go or Rust or OO A&D or agile programming or ...) solves all problems. Each of those are good things, which move the needle, but progress is and remains incremental.
 
EMACS is an all-purpose text editor, at least for me. You might prefer to use an IDE because it sets up the development tools so you have more time to think about software concepts.
I was going to say that an IDE is potentially a negative distraction for beginners. Especially since a number of them really muddy up the interaction between the compilers / linkers when it comes to learning. Just a text editor and command prompt / compiler is more than enough to forcus on the software concepts.

However yeah, I think learning EMACS / vi(m) whilst learning programming is certainly a distraction. Those should really have been taught at secondary school IT classes in my opinion.
 
1) What programming code is most used by FBSD developers?

2) Is this the most useful code for a beginner to start off with?

3) Most beginner programming resources seem to use default teaching methods but seem to be silent on the most basic elements that make up blocks of code. Is there a dictionary for these most basic elements.

4) As a teaching tool could blocks of programming code be written in parallel with one's native language & make sense. It would be great if the two could be sensibly linked, even though it might be otherwise boring.

5) What beginner's resource would you recommend for wring fbsd code?
They used C to code system but it depends to what you will do too. You can use Java, Python etc. Some libraries not works on FreeBSD like "opencv" when tried to install with pip but I guess these can work when build over source too. C is not a good language for begineers in my opinion but if you can learn C or if you already know you can help to FreeBSD's development, change things on system as you want and things like that
 
Theoretically, you are right. If we only had supergeniuses as programmers, and we had infinite time to review code and argue over every statement, then even C code would not have any memory management bugs.
Explicit memory management can go horribly wrong, but you really don't need "supergeniuses" to avoid that, neither do you have to reason over every single statement.

What you need is simply a solid design (think before you code) where ownership of data is always clear. It must be clear when ownership is passed on to some other "module", it must also be clear when you might have to copy the data instead of just passing a pointer.

Garbage collectors condition programmers to not even think about these things. This saves some time, but I'm not sure it's always beneficial for the overall design of the code.
 
What you need is simply a solid design (think before you code) where ownership of data is always clear. It must be clear when ownership is passed on to some other "module", it must also be clear when you might have to copy the data instead of just passing a pointer.
There have been 154,463 CVEs since 1999. If only all those people had known it's actually this simple.
 
There have been 154,463 CVEs since 1999. If only all those people had known it's actually this simple.
We have had garbage collected languages for years (including both C and C++ with Boehm's GC). How come CVE's still exist?
Why is Java written in C and C++?

Garbage collectors condition programmers to not even think about these things. This saves some time, but I'm not sure it's always beneficial for the overall design of the code.
I suppose for those who don't specifically focus on programming but need to script something, a GC is ideal. Likewise for more abstract things like lots of text processing where there is no real concept of a "system architecture".

However for software engineering specifically, I think a GC is potentially unnecessary and many of its roles can be solved via design. Typically software should be designed in such a way that lifetimes are known and deterministic. Or at the very least engineers choose Java, VB.NET, etc, not necessarily because of the memory management but for the other benefits.

That said, I wish GCs would be used more as debuggers to notify developers of circular references, use after free, etc. I could really do with that.

Though arguably C++'s RAII mechanism is a form of garbage collector. Though we tend to think of tracing garbage collectors when we discuss it.
 
If you combine it with the fact that the Java software is all documented inline (using JavaDoc), it made scripting access to a huge running system super convenient.
I'm a huge fan of Javadoc. I always had it open in a tab or a browser window in the days before tabs. It's built into most IDEs now, so all you have to do is hover over the class or method, and the Javadoc for it pops up. It was such a huge relief to not have to remember all the wrinkles of every API. I imagine there would've been far fewer problems with things like strcpy() if C had something like Javadoc. Doxygen kind of works, but the comparison has always been sad-making for me.
Works great, until someone decides to write tight loops in JPython, which do string manipulation. That overwhelmed the Java garbage collector so badly, it was (like you said) sometimes stopping for 30 seconds at a time.
It's funny how often performance problems turn out to be related to string manipulation. The same thing happened to the inventors of Lua:
We expected our ORB tobe somewhat slower, as it was implemented in Lua, but we were disappointed by how much slower it was. At first, we just laid the blame on Lua. Later, we suspected that the culprit could be all those operations needed to serialize each number. So, we decided to run the program under a profiler...Against our gut feelings, the serialization of numbers had no measurable impact on the performance, among other reasons because there were not that many numbers to serialize. The serialization of strings, however, was responsible for a huge part of the total time.
What you need is simply a solid design (think before you code) where ownership of data is always clear. It must be clear when ownership is passed on to some other "module", it must also be clear when you might have to copy the data instead of just passing a pointer.
My experience with C is that ownership is very often not clear; not only in practice, but in principle. I run into this almost immediately doing simple things like trying to log an error message. I personally prefer reference-counting to either explicit memory management or garbage collection.
 
My experience with C is that ownership is very often not clear; not only in practice, but in principle. I run into this almost immediately doing simple things like trying to log an error message. I personally prefer reference-counting to either explicit memory management or garbage collection.
That's a scenario where I indeed had to think a bit when I wanted to log asynchronously (as syslog(3) can block). I decided to just take a copy of the log message. Yes, that's not the most efficient way of course ;)
 
Garbage collectors condition programmers to not even think about these things. This saves some time, but I'm not sure it's always beneficial for the overall design of the code.
Just last week I entered my card number into a commercial website and hit the Submit button, only to be greeted by a message that said "NullReferenceException: Object Reference Not Set to an instance of an object." That did not inspire confidence. From that lived experience, I can only conclude that garbage-collected languages are all terrible and nobody should ever use them for any purpose whatsoever. ;)
 
Back
Top