Author Topic: understand c programming logic but can't write a tough program  (Read 5638 times)

0 Members and 1 Guest are viewing this topic.

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: understand c programming logic but can't write a tough program
« Reply #25 on: March 02, 2020, 04:11:47 pm »
In terms of formatting, Microsoft Visual Studio does a nice job as does Visual Studio Code.

 

Offline SilverSolder

  • Super Contributor
  • ***
  • Posts: 6126
  • Country: 00
Re: understand c programming logic but can't write a tough program
« Reply #26 on: March 02, 2020, 04:31:01 pm »
After about 30 or 40 years of this, you get to the point where you can write quite long programs that compile the first time  (notice, I didn't say "work" the first time!)   :-DD
Something to laugh about there?

There are some things so serious, we can ONLY laugh at them!  -- Niels Bohr
 

Offline hwj-d

  • Frequent Contributor
  • **
  • Posts: 676
  • Country: de
  • save the children - chase the cabal
Re: understand c programming logic but can't write a tough program
« Reply #27 on: March 02, 2020, 06:10:09 pm »
After about 30 or 40 years of this, you get to the point where you can write quite long programs that compile the first time  (notice, I didn't say "work" the first time!)   :-DD
Something to laugh about there?
There are some things so serious, we can ONLY laugh at them!  -- Niels Bohr

Buddy, you are annoying to trigger someone. Try to find a new girlfriend.
 

Offline SilverSolder

  • Super Contributor
  • ***
  • Posts: 6126
  • Country: 00
Re: understand c programming logic but can't write a tough program
« Reply #28 on: March 02, 2020, 06:27:52 pm »
After about 30 or 40 years of this, you get to the point where you can write quite long programs that compile the first time  (notice, I didn't say "work" the first time!)   :-DD
Something to laugh about there?
There are some things so serious, we can ONLY laugh at them!  -- Niels Bohr

Buddy, you are annoying to trigger someone. Try to find a new girlfriend.

You are taking this the wrong way.

The issue of writing correct / functional programs is not new, and will remain an issue for a long time.  It is beyond our power to solve easily, hence the Niels Bohr quote.


 

Offline emece67

  • Frequent Contributor
  • **
  • !
  • Posts: 614
  • Country: 00
Re: understand c programming logic but can't write a tough program
« Reply #29 on: March 02, 2020, 10:40:33 pm »
.
« Last Edit: August 19, 2022, 03:45:37 pm by emece67 »
 

Offline hwj-d

  • Frequent Contributor
  • **
  • Posts: 676
  • Country: de
  • save the children - chase the cabal
Re: understand c programming logic but can't write a tough program
« Reply #30 on: March 03, 2020, 02:55:00 am »
After about 30 or 40 years of this, you get to the point where you can write quite long programs that compile the first time  (notice, I didn't say "work" the first time!)   :-DD
Something to laugh about there?
There are some things so serious, we can ONLY laugh at them!  -- Niels Bohr

Buddy, you are annoying to trigger someone. Try to find a new girlfriend.

You are taking this the wrong way.

The issue of writing correct / functional programs is not new, and will remain an issue for a long time.  It is beyond our power to solve easily, hence the Niels Bohr quote.
Maybe.
It's up to you, to express yourself more clearly. I specifically asked again.
In the text: "someone" and "you" has different meanings, apart from the fact that english/american is not my native language. Shit happens.  ;)
 

Offline SilverSolder

  • Super Contributor
  • ***
  • Posts: 6126
  • Country: 00
Re: understand c programming logic but can't write a tough program
« Reply #31 on: March 03, 2020, 02:59:18 am »
After about 30 or 40 years of this, you get to the point where you can write quite long programs that compile the first time  (notice, I didn't say "work" the first time!)   :-DD
Something to laugh about there?
There are some things so serious, we can ONLY laugh at them!  -- Niels Bohr

Buddy, you are annoying to trigger someone. Try to find a new girlfriend.

You are taking this the wrong way.

The issue of writing correct / functional programs is not new, and will remain an issue for a long time.  It is beyond our power to solve easily, hence the Niels Bohr quote.
Maybe.
It's up to you, to express yourself more clearly. I specifically asked again.
In the text: "someone" and "you" has different meanings, apart from the fact that english/american is not my native language. Shit happens.  ;)

Kein problem!  :)
 

Offline hwj-d

  • Frequent Contributor
  • **
  • Posts: 676
  • Country: de
  • save the children - chase the cabal
Re: understand c programming logic but can't write a tough program
« Reply #32 on: March 03, 2020, 03:06:59 am »
 :-+
 

Offline hwj-d

  • Frequent Contributor
  • **
  • Posts: 676
  • Country: de
  • save the children - chase the cabal
Re: understand c programming logic but can't write a tough program
« Reply #33 on: March 03, 2020, 03:40:24 am »
After about 30 or 40 years of this, you get to the point where you can write quite long programs that compile the first time  (notice, I didn't say "work" the first time!)   :-DD
Something to laugh about there?
There are some things so serious, we can ONLY laugh at them!  -- Niels Bohr

Buddy, you are annoying to trigger someone. Try to find a new girlfriend.

You are taking this the wrong way.

The issue of writing correct / functional programs is not new, and will remain an issue for a long time.  It is beyond our power to solve easily, hence the Niels Bohr quote.
Maybe.
It's up to you, to express yourself more clearly. I specifically asked again.
In the text: "someone" and "you" has different meanings, apart from the fact that english/american is not my native language. Shit happens.  ;)

Kein problem!  :)
Do we know each other from stuttgart?
 

Online Nominal Animal

  • Super Contributor
  • ***
  • Posts: 6265
  • Country: fi
    • My home page and email address
Re: understand c programming logic but can't write a tough program
« Reply #34 on: March 03, 2020, 05:56:21 am »
Experimenting with problems that interest yourself is a good way to progress.

For example, I am lazy.  I want to do things well enough to trust them, so I can do other, more interesting stuff without worrying about falling down because of shoddy earlier work.  This means I am well suited for low-level, system/OS/library level work, but not as fast as others when it comes to user interfaces or mockups.

If you are interested in mathematics, then the various methods of calculating Fibonacci numbers is an excellent opportunity for testing different things, and learning how to solve problems via computer programs.

You have the standard recursive algorithm.  It is simple to implement, but slow.
You also have the iterative method (remembering the two previous numbers, calculating the next one, and forgetting the oldest number).  It is simple to implement, but has to iterate from F1 to the desired Fibonacci number.
The next step up is using an array to hold the previously calculated Fibonacci numbers.
The next step up is using the mathematical properties of the series, namely
$$\begin{aligned}
F_{2 n - 1} &= F_{n}^2 + F_{n-1}^2 \\
F_{2 n} &= \left(2 F_{n-1} + F_{n} \right) F_{n} \\
\end{aligned}$$
which lets you calculate any Fibonacci number in logarithmic time and space complexity.
The next step up is direct calculation of any Fibonacci number, using
$$F_n = \frac{\varphi^n - (-\varphi)^{-n}}{\sqrt{5}}$$
and if using truncation (as C uses for integers, for example),
$$F_n = \left\lfloor \frac{\varphi^n}{\sqrt{5}} + \frac{1}{2} \right\rfloor$$
where $$\varphi = \frac{1 + \sqrt{5}}{2} \approx 1.61803$$
The next step up is to realize the limits of the hardware number types (integer and floating-point types), and to write your own bignum (for the logarithmic, integer-based method) or arbitrary-precision (for the direct evaluation) implementation.  At that point, we're writing GNU Scientific Library style code, and well and truly deep into programming, typically with a decade or more practical experience.  So, this is not a series of exercises, but rather a simple problem you can attack again and again, whenever you feel the need or inspiration to develop or hone your skills.

The same goes for most practical problems as well.  One of my old-timey favourites is the venerable sort command, which in general terms accepts input as lines, and outputs them in sorted order.  It is an excellent real-world test for many sort algorithms, because it is a real-world task.  It shows very clearly how some algorithms work best when the data is almost sorted, how some algorithms have weak points (like if the input is in opposite order to output; rare but occasionally occurring situation).  Very informative.

The reason I like it is because when you overcome the need to optimize code, and get to the stage where programs are just tools you wield as easily as you might wield a fork or a spoon, you start looking at what to optimize to get the most bang for your effort; you're essentially optimizing your optimization efforts, for the results to be most useful to you or your users.  Because mass storage is still at least one order of magnitude (10x) slower than working memory (RAM), it turns out that if we want to minimize the real-world time it takes for the data to be output -- i.e. the time the human running the command has to wait, if it is run interactively --, it is better to waste some efficiency in order to increase the throughput.  You do this by reading each line into a sorting abstract data type; usually a tree or a heap.  This way, more CPU time is used in sorting the data, but because each line is sorted as soon as it is read, and the sorting takes typically less time than reading the line into working memory, the entire job takes less real-world time to complete.  The CPU just worked a bit harder, that's all.  (This is obviously not true if the data to be sorted is already in working memory; then, it would be best to just copy the data over, and then run the most efficient sorting algorithm on it.)

Sorting data in itself is a tricky subject, because in most real world cases, the actual amount of unique inputs is limited.  This means that sorting ints, longs, floats, or even doubles is perfectly possible to do in linear time, even though it has been proven that mathematically, logarithmic time is optimum.  The reason is that radix sorting does its work in linear time if there is a limited number of possible input values.  So, given enough data, it will beat all other sort algorithms.  Currently, the breakover point is somewhere around millions of doubles, with typical common sort algorithms like QuickSort being faster for smaller amounts of data.  Again, if you have useful information on the real-world data to be sorted, you can make the typical cases very fast, with some other cases slower than optimum.  This means that a very good programmer (or "software architect", designer, problem-solver, or whatever; not the code monkey, but the person who decides how the program solves the problems it needs to solve), has to be aware of 1) real-world needs, 2) possible algorithms and tools (to have as wide selection as possible, instead of treating all problems the same), and 3) of the hardware possibilities.

But even more importantly, a good programmer is always learning more.  Because you never know enough.

It all starts from interest in problem solving.  Anything and everything you can learn about that, will help.  I'm not talking only about problem solving via computer programs, but even oddball tricks like how to solve a Rubik's Cube in an orderly fashion is really just an algorithm, and understanding how different algorithms work, is like getting new tools in your toolbox.  Then you use those different tools on various problems you are interested in, to see how they work.  Real-world experience beats theoretical knowledge every time, so expect to do a lot of this, basically for the rest of your life.  Fortunately, it is both fun and rewarding!
« Last Edit: March 03, 2020, 05:58:30 am by Nominal Animal »
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: understand c programming logic but can't write a tough program
« Reply #35 on: March 03, 2020, 07:17:30 am »
Quote
I'd object to step 7 ["make it pretty"] on principle because if you have that step at all, it never ends up being done in the real world
I dunno.  If your ISO9000 process says your software needs DOxygen comments, this is the place where you carefully fiddle with the comments you've already written (right?) to make them look good in the documentation.  It's where you flush things out so that the Junior Engineers won't have trouble understanding it.  Check for all those dangerous strcpy() and replace them with buffer-overflow-protected, thread-safe, etc versions.   All the stuff that would theoretically be detected in a thorogh code review that you didn't pay that much attention to because you were focussing on THE PROBLEM.

And there is also the non-real world.  Academia and Publication, when you'll (hopefully) want a much better level of "prettiness" than the real world would require.


Quote
you get to the point where you can write quite long programs that compile the first time
Interesting.  I've reflected that I frequently don't pay much attention to whether I've made minor syntax errors on initial program entry.  Because, after all, the compiler will tell me about them real quick, anyway.  (of course, occasionally such errors are NOT detected and result in hard-to-find problems, and that's annoying...)
 

Offline hwj-d

  • Frequent Contributor
  • **
  • Posts: 676
  • Country: de
  • save the children - chase the cabal
Re: understand c programming logic but can't write a tough program
« Reply #36 on: March 03, 2020, 08:03:57 am »
Experimenting with problems that interest yourself is a good way to progress.

For example, I am lazy.  I want to do things well enough to trust them, so I can do other, more interesting stuff without worrying about falling down because of shoddy earlier work.  This means I am well suited for low-level, system/OS/library level work, but not as fast as others when it comes to user interfaces or mockups.
...
Yeah, have you ever seen an original win3.1 SDK in a 1.5m long bookshelf? At these early times I programmed an original hp32s with nearly original outer dimensions and dot-matrix scrolling display to learn it. This calculator serves me a long time, and I have it functional these win10 times too. That's my learning by doing with a practical background. ;)
 

Online Nominal Animal

  • Super Contributor
  • ***
  • Posts: 6265
  • Country: fi
    • My home page and email address
Re: understand c programming logic but can't write a tough program
« Reply #37 on: March 03, 2020, 08:17:01 am »
Yeah, have you ever seen an original win3.1 SDK in a 1.5m long bookshelf?
No, but I did have a '286 in the DOS era, before Windows, and learned Pascal on it.  Was my second computer.  The first one was a C128.

This calculator serves me a long time, and I have it functional these win10 times too. That's my learning by doing with a practical background. ;)
Sure, but having and keeping an useful tool is slightly different to learning programming by doing.  I meant that practice is necessary for learning and honing ones skill, not that doing something like that, or maintaining calculator software across decades, necessarily makes you an excellent programmer :P

Knowing the importance of good, reliable tools, and treating your own programs as such, seems to help, though.
 

Offline hwj-d

  • Frequent Contributor
  • **
  • Posts: 676
  • Country: de
  • save the children - chase the cabal
Re: understand c programming logic but can't write a tough program
« Reply #38 on: March 03, 2020, 08:24:52 am »
Yeah, have you ever seen an original win3.1 SDK in a 1.5m long bookshelf?
No, but I did have a '286 in the DOS era, before Windows, and learned Pascal on it.  Was my second computer.  The first one was a C128.

This calculator serves me a long time, and I have it functional these win10 times too. That's my learning by doing with a practical background. ;)
Sure, but having and keeping an useful tool is slightly different to learning programming by doing.  I meant that practice is necessary for learning and honing ones skill, not that doing something like that, or maintaining calculator software across decades, necessarily makes you an excellent programmer :P

Knowing the importance of good, reliable tools, and treating your own programs as such, seems to help, though.
Did you noticed, that i programed this thing by my own from scratch?  :D
Edit: And SDK means that elementar Software Development Kit for handling all these fundamental ms-routines and parameters and all this new methods for  TrueType, OLE, DragDrop, Mulitastking at this time, that came on paper and a bunch of CD's. That was not Borland Pascal :D
« Last Edit: March 03, 2020, 08:47:36 am by hwj-d »
 

Offline SilverSolder

  • Super Contributor
  • ***
  • Posts: 6126
  • Country: 00
Re: understand c programming logic but can't write a tough program
« Reply #39 on: March 03, 2020, 12:46:55 pm »
After about 30 or 40 years of this, you get to the point where you can write quite long programs that compile the first time  (notice, I didn't say "work" the first time!)   :-DD
Something to laugh about there?
There are some things so serious, we can ONLY laugh at them!  -- Niels Bohr

Buddy, you are annoying to trigger someone. Try to find a new girlfriend.

You are taking this the wrong way.

The issue of writing correct / functional programs is not new, and will remain an issue for a long time.  It is beyond our power to solve easily, hence the Niels Bohr quote.
Maybe.
It's up to you, to express yourself more clearly. I specifically asked again.
In the text: "someone" and "you" has different meanings, apart from the fact that english/american is not my native language. Shit happens.  ;)

Kein problem!  :)
Do we know each other from stuttgart?

No, I have not been to Stuttgart for many years.   I live in the USA and the UK.  Funnily enough, I heard a teenage boy speaking German at an American supermarket this weekend.  I asked him where learned.  "School."  -  He also knew a bit of Norwegian.  I like it when young people show an interest in other cultures and languages.  There's not enough of it.
 

Offline hwj-d

  • Frequent Contributor
  • **
  • Posts: 676
  • Country: de
  • save the children - chase the cabal
Re: understand c programming logic but can't write a tough program
« Reply #40 on: March 03, 2020, 05:12:59 pm »
...
Do we know each other from stuttgart?

No, I have not been to Stuttgart for many years.   I live in the USA and the UK.  Funnily enough, I heard a teenage boy speaking German at an American supermarket this weekend.  I asked him where learned.  "School."  -  He also knew a bit of Norwegian.  I like it when young people show an interest in other cultures and languages.  There's not enough of it.
Ok, thanks. We had an EEVblog-Meeting last year with some members in Stuttgart.
 

Offline SilverSolder

  • Super Contributor
  • ***
  • Posts: 6126
  • Country: 00
Re: understand c programming logic but can't write a tough program
« Reply #41 on: March 03, 2020, 06:11:25 pm »
...
Do we know each other from stuttgart?

No, I have not been to Stuttgart for many years.   I live in the USA and the UK.  Funnily enough, I heard a teenage boy speaking German at an American supermarket this weekend.  I asked him where learned.  "School."  -  He also knew a bit of Norwegian.  I like it when young people show an interest in other cultures and languages.  There's not enough of it.
Ok, thanks. We had an EEVblog-Meeting last year with some members in Stuttgart.

Ah, well now there's a good excuse to go to Stuttgart!  :)
 

Online Nominal Animal

  • Super Contributor
  • ***
  • Posts: 6265
  • Country: fi
    • My home page and email address
Re: understand c programming logic but can't write a tough program
« Reply #42 on: March 03, 2020, 09:57:43 pm »
Did you noticed, that i programed this thing by my own from scratch?  :D
No, I missed that.  But that makes it an excellent example of what I meant about being fundamentally lazy!  Do it well enough it from the get go, so you can trust it :)

Edit: And SDK means
I know; I just chose to not work with Windows low-level stuff.  In the 1996-2003 timeframe, I did mostly internet stuff (both server and client-side; not just HTTP/HTML, but FTP and file servers too), and some interactive cross-platform multimedia with Shockwave Internet Studio.  I did have a work machine with Windows till 2003 or so, but used Linux more since 1997 or so; completely switched to Linux in 2003 or thereabouts.

Before Windows came to the market, I did use Borland Pascal for a couple of commercial programs for MS-DOS.  For one, I did copy protection by rewriting the EXE relocator code, using debug.exe, because I had neither TASM nor MASM available. I did have binders full of descriptive geometry, computer graphics (math side) stuff, as well as Ralf Brown's Interrupt List...  Now that one was absolutely amazing!
 

Offline hwj-d

  • Frequent Contributor
  • **
  • Posts: 676
  • Country: de
  • save the children - chase the cabal
Re: understand c programming logic but can't write a tough program
« Reply #43 on: March 04, 2020, 03:07:57 am »
Did you noticed, that i programed this thing by my own from scratch?  :D
No, I missed that.  But that makes it an excellent example of what I meant about being fundamentally lazy!  Do it well enough it from the get go, so you can trust it :)
Don't really know, what you mean with "lazy". That's a nice passing time on the side.

At this time, a little later, i had taken the MCSE examinations(NT) by myself because I needed them for my independence.  That included TCP/IP as well as MS-Server in the enterprise. That don't stop there. Heterogen administration of UNIX like network, FreeBSD, and I became a special programmer for implementing applications (RFC, GnuPGP, and all the protocol-stuff arround) and a forensic analyser. After that I'm a professional IT-consult. But yes, it originally started with 6502(Kim) 8085/Z80 (Nascom) and understanding their 8-bit architecture, hardware and assembler programming. Since that time I still have a penchant for hardware and analog electronics, so i'm here in the blog.  ;D
 
Edit:
I know; I just chose to not work with Windows low-level stuff.  In the 1996-2003 timeframe, I did mostly internet stuff (both server and client-side; not just HTTP/HTML, but FTP and file servers too), and some interactive cross-platform multimedia with Shockwave Internet Studio.  I did have a work machine with Windows till 2003 or so, but used Linux more since 1997 or so; completely switched to Linux in 2003 or thereabouts.

Before Windows came to the market, I did use Borland Pascal for a couple of commercial programs for MS-DOS.  For one, I did copy protection by rewriting the EXE relocator code, using debug.exe, because I had neither TASM nor MASM available. I did have binders full of descriptive geometry, computer graphics (math side) stuff, as well as Ralf Brown's Interrupt List...  Now that one was absolutely amazing!

Similar for me, except for the graphic stuff, but more RFC and network protocols.
But it's been a while ...
 

Offline SilverSolder

  • Super Contributor
  • ***
  • Posts: 6126
  • Country: 00
Re: understand c programming logic but can't write a tough program
« Reply #44 on: March 04, 2020, 12:02:38 pm »
Did you noticed, that i programed this thing by my own from scratch?  :D
No, I missed that.  But that makes it an excellent example of what I meant about being fundamentally lazy!  Do it well enough it from the get go, so you can trust it :)
Don't really know, what you mean with "lazy". That's a nice passing time on the side.

At this time, a little later, i had taken the MCSE examinations(NT) by myself because I needed them for my independence.  That included TCP/IP as well as MS-Server in the enterprise. That don't stop there. Heterogen administration of UNIX like network, FreeBSD, and I became a special programmer for implementing applications (RFC, GnuPGP, and all the protocol-stuff arround) and a forensic analyser. After that I'm a professional IT-consult. But yes, it originally started with 6502(Kim) 8085/Z80 (Nascom) and understanding their 8-bit architecture, hardware and assembler programming. Since that time I still have a penchant for hardware and analog electronics, so i'm here in the blog.  ;D
 
Edit:
I know; I just chose to not work with Windows low-level stuff.  In the 1996-2003 timeframe, I did mostly internet stuff (both server and client-side; not just HTTP/HTML, but FTP and file servers too), and some interactive cross-platform multimedia with Shockwave Internet Studio.  I did have a work machine with Windows till 2003 or so, but used Linux more since 1997 or so; completely switched to Linux in 2003 or thereabouts.

Before Windows came to the market, I did use Borland Pascal for a couple of commercial programs for MS-DOS.  For one, I did copy protection by rewriting the EXE relocator code, using debug.exe, because I had neither TASM nor MASM available. I did have binders full of descriptive geometry, computer graphics (math side) stuff, as well as Ralf Brown's Interrupt List...  Now that one was absolutely amazing!

Similar for me, except for the graphic stuff, but more RFC and network protocols.
But it's been a while ...

My "gateway drug" was an Acorn Atom (6502)...   Guess that processor has a lot to answer for!  ;D

 

Offline brucehoult

  • Super Contributor
  • ***
  • Posts: 4039
  • Country: nz
Re: understand c programming logic but can't write a tough program
« Reply #45 on: March 04, 2020, 07:48:35 pm »
My "gateway drug" was an Acorn Atom (6502)...   Guess that processor has a lot to answer for!  ;D

The 6502 is a horrid little CPU. It uses an incredibly small number of transistors but is worse to program on than all the other 8 bit processors except .. hmm .. 8080, z80, 6800, 2650, SC/MP, 8051, PIC and no doubt some others I've suppressed memories of.

Let me rephrase that .. the 6502 is better than all 8 bit processors except the AVR (which came much much later) and 6809 (which is close to being an 8088 without segment registers, except faster)
 
The following users thanked this post: SilverSolder

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: understand c programming logic but can't write a tough program
« Reply #46 on: March 04, 2020, 08:44:44 pm »
I certainly wouldn't prefer a 6502 to a Z80 (or even an 8080) but that's just me.  I did a bunch of work attaching early hard drives to Apple IIs and, of course, the driver had to run on a 6502.  Maybe I just didn't have enough time in grade.

I started with the Altair 8800 when it first came out and got pretty well indoctrinated into the 8080 way of doing things.  The progression to the Z80 was fairly straightforward.

Several years ago, I bought one of the new Zilog eZ80 boards where the processor runs at 50 MHz.  I build a daughter card to hold a Compact Flash device and two FTDI seriel<->USB chips (before the newer 4 channel devices) and I can tell you, a 50 MHz CPU makes CP/M scream!

No, I would never pick up a 6502 but I still mess with Z80 stuff via RC2014 projects.

https://rc2014.co.uk/

I have 3 of their systems - each different in capability but one runs CP/M.
 

Offline gbaddeley

  • Regular Contributor
  • *
  • Posts: 205
  • Country: au
Re: understand c programming logic but can't write a tough program
« Reply #47 on: March 04, 2020, 08:56:28 pm »
As a C programmer for 25+ years (and a slew of other languages), it pays to format (pretty) and document from the very start. Investing a little time has big dividends when you (or someone else) needs to look at the code in the future. It should be easy to follow and make logical sense. Extensive comments & documentation  are not always productive. They should aid in code readability, that’s all.
Glenn
 
The following users thanked this post: grizewald

Online Nominal Animal

  • Super Contributor
  • ***
  • Posts: 6265
  • Country: fi
    • My home page and email address
Re: understand c programming logic but can't write a tough program
« Reply #48 on: March 04, 2020, 09:46:52 pm »
Don't really know, what you mean with "lazy".
Do the thing well enough from the get go, so that you can trust it later on, instead of wasting time fixing small bugs all the time.

It also leads to the KISS principle and Unix philosophy.  Works well for me.

Nowadays, I mostly do C/POSIX/GNU low-level stuff, and Python for UIs.
 

Online Nominal Animal

  • Super Contributor
  • ***
  • Posts: 6265
  • Country: fi
    • My home page and email address
Re: understand c programming logic but can't write a tough program
« Reply #49 on: March 04, 2020, 10:10:50 pm »
Extensive comments & documentation [...] should aid in code readability, that’s all.
I like to emphasize that the comments should describe the programmer intent; the things you cannot read from the code itself.

Commenting what the code does is unhelpful, as reading the code tells that already; we don't want to have to read it twice.
But reading a comment that describes the general idea behind the operation (like "sort the given array using the QuickSort algorithm") or the reason why a specific detail must be just so ("we need to hold the foo lock while calling this function, because otherwise we can deadlock with baz"), those are helpful.

Even after three decades, I am still trying to learn how to write more useful comments.  I wish someone had pointed out their importance earlier on!
 
The following users thanked this post: SilverSolder, grizewald


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf