Author Topic: while loop in software  (Read 64847 times)

0 Members and 1 Guest are viewing this topic.

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5550
  • Country: us
Re: while loop in software
« Reply #250 on: January 06, 2015, 07:02:41 am »
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6189
  • Country: us
Re: while loop in software
« Reply #251 on: January 06, 2015, 07:34:51 am »
well...

https://go.googlesource.com/go/+/go1.4/src/lib9/

It is built on solid foundations ;-) 

Have you played with it? It's supposed to solve the deployment hassle of Java. AFAIK no portable GUI library yet so this is a drawback.

 

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5550
  • Country: us
Re: while loop in software
« Reply #252 on: January 06, 2015, 07:40:12 am »
Only plan9 I've looked at was rudp (as in reliable udp) did not use it, just curiosity and didn't look too good, but this was a while back so I don't recall what I didn't like.

Funny thing I didn't see an rudp.c in that directory ;)

Edit: but to answer your question, I didn't use go and didn't collect $200 :)
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4192
  • Country: us
Re: while loop in software
« Reply #253 on: January 06, 2015, 08:04:59 am »
Didn't Apple write their system software in a Pascal variant, back in the 68000 days?
I suppose that somewhere there is an interesting story about what happened to cause them to change their minds. (has it been made public, that anyone knows?)
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 26682
  • Country: nl
    • NCT Developments
Re: while loop in software
« Reply #254 on: January 06, 2015, 01:43:53 pm »
A good C/C++ compiler inlines short functions anyway so there is no need to do the compiler's work.
A good C compiler will do much for you, they have come a looong way, certainly.

Since C isn't type safe nor memory safe (and languages have existed since the early 1970s which are) I will cling hopelessly to my distaste for the language.
I hear you  ;) I hope to continue my adventure with Lua on an ARM microcontroller in the near future!
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline paf

  • Regular Contributor
  • *
  • Posts: 91
Re: while loop in software
« Reply #255 on: January 15, 2015, 09:43:29 am »
for ( i=0, ptr=array, bError=FALSE; i<10 && !bError; i++, ptr++)

If I was the reviewer of that code it would never make it into production or even source control. Just because you can, does not mean it's a good idea to rape a for loop.

I even demand changing simple thing like:

if (0 < x)

to

if (x > 0)

just for the sake of general easy readability. It's all about people maintaining the code in the future not wasting time because it was written by someone thinking it was cool to write in that style.

Hmm, actually, this has a place in defensive programming, but for the test of equality.

Consider

if (x == 1)

A common typo is

if (x = 1)

which compiles without warning (on most compilers I use anyway). This code does something totally different and usually is undesired.

If you change this to:

if (1 == x)

instead, the typo

if (1 = x)

declares an error, as you cannot assign x to a constant. So once you get into this habit,

if (0 < x)

is a natural extension, and good practice to reducing coding errors.

No, no, no.

Any decent C compiler will warn you that  you have an assignment used as a truth value if you write things like if (x = 1).

GCC and Clang ail warn you, and that covers ARM, AVR, MIPS (PiC32), MSP430 and others.


If you are programming in C:

Turn on all the compiler warnings.

Pass your code through splint    [url=http://www.splint.org/]http://www.splint.org/[/url]

If possible check it with Valgrind    [url=http://valgrind.org/]http://valgrind.org/[/url]

Thanks

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf