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

0 Members and 1 Guest are viewing this topic.

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6190
  • Country: us
Re: while loop in software
« Reply #150 on: December 20, 2014, 03:42:08 pm »
So we agree, that while() loops in C are a religious matter? >:D

To answer this question we first need to determine if C itself is good. :)
 

Offline madires

  • Super Contributor
  • ***
  • Posts: 7763
  • Country: de
  • A qualified hobbyist ;)
Re: while loop in software
« Reply #151 on: December 20, 2014, 04:03:17 pm »
So we agree, that while() loops in C are a religious matter? >:D

To answer this question we first need to determine if C itself is good. :)

Intentional spelling error?  ;D

Sorry, couldn't resist.
 

Offline f1rmb

  • Regular Contributor
  • *
  • Posts: 180
  • Country: fr
Re: while loop in software
« Reply #152 on: December 20, 2014, 08:43:32 pm »
go for visual basic 6 my friend... it has array bound check in every compile option, your problem solved!
Every C compiler has a bounds check flag you can enable if you want.
BTW, is VB even a language? :-D
It's not even portable [emoji14]alm:
---
Daniel
VB hateboy (linux/mac/c fanboy) joining the club, welcome!... yes VB is a language, you seem to miss what a "language" means. and i'm guessing you are the new guy or never code in VB, never link it to external C/asm (read as super fast and efficient) code/dll, and never get the idea that there is/are few VB IDE for micros, never appreciate how hard the hundreds lines of code just for windows creation and events handling etc... granted there is no VB for linux or mac because VB was invented by the "BIG" guy from M$$$$. mac & linux are small, if it aint for W$$$ i'm not buying [emoji14] [emoji14] [emoji14] you taste what? lemon? [emoji14]

edit: and i dont need to be portable because i can live without linux and mac. and portabilitty is not something you embed or as a criterion in a language, it can be important for the success of a particular language, but not that important to decide whether one is a language or not. portability is about people providing platform or IDE / compiler for the particular machine. if the big guy decided VB to be portable, they will build the IDE for other OS, but they opt to not to. if no one is building java distribution for windows, java app will not even be portable to windows, you feel that?
Thanks, but here you're wrong. Back in the day, I even used VB (you known,  installing that from zillion of 3"5 floppy), few years ago I had to use it again for some obscure quick and crap proof of concept (yeah,  rewrote the whole this in C++ right after that). So yes, VB is much more a toy ("variant" data(no)type, what a shame) than anything else, these various incompatible runtime you have to install are just PITA. yeah, it's fast and easy to build a window with menu and buttons, but that's it. You want something fast with small memory footprint, try something else, like a real programming language (GFA basic? :-D)

Portability, yeah, that's the key, you know, there are other worlds out of Windows, open you mind.
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11630
  • Country: my
  • reassessing directives...
Re: while loop in software
« Reply #153 on: December 21, 2014, 12:16:04 am »
Back in the day, I even used VB (you known,  installing that from zillion of 3"5 floppy) ... You want something fast with small memory footprint, try something else, like a real programming language (GFA basic? :-D)
GFA Basics? seriously?


man dont drag me to your floppy era, i'm done with it. VB today is not the same as VB 20yrs ago. even VB6 is now comparatively alot smaller footprint than say.... java w it distribution (aka runtime environment), NET4 et al the new modernization of computing theology, i cant understand why people are so care about exe footprint anymore in terrabytes era. and my quote on you dont understand what is a "language" because VB is based on "Basic Language", Basic is the language, "Visual" is just the whistle of it. you just like saying "Borland C++" is not a language because it has "Borland" in it. VB and GFA Basics are based on the same language... "Basic". dont recommend VB? dont recommend GFA ;)

few years ago I had to use it again for some obscure quick and crap proof of concept
if hate it, why use it? why dont just build "the proof of concept" right from the start in C? then you dont have to rewrite? or either.. since you build "crap proof of concept", your concept is actually crap? ;)

just for the record, to compare between floppy and "not so modern" era, vb6 somewhere in 2000... i was talking building app for windows, not DOS.

Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11630
  • Country: my
  • reassessing directives...
Re: while loop in software
« Reply #154 on: December 21, 2014, 12:26:10 am »
So we agree, that while() loops in C are a religious matter? >:D
To answer this question we first need to determine if C itself is good. :)
Intentional spelling error?  ;D
:-DD
Nature: Evolution and the Illusion of Randomness (Stephen L. Talbott): Its now indisputable that... organisms “expertise” contextualizes its genome, and its nonsense to say that these powers are under the control of the genome being contextualized - Barbara McClintock
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6190
  • Country: us
Re: while loop in software
« Reply #155 on: December 21, 2014, 12:30:05 am »
So we agree, that while() loops in C are a religious matter? >:D

To answer this question we first need to determine if C itself is good. :)

Intentional spelling error?  ;D

Sorry, couldn't resist.

Yes, I meant dog.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: while loop in software
« Reply #156 on: December 21, 2014, 03:38:09 am »
Quote
already 10 pages of  :rant: on while loops,
Well, in fact, No.   Distracted by Trolls, I think.
 

Offline f1rmb

  • Regular Contributor
  • *
  • Posts: 180
  • Country: fr
Re: while loop in software
« Reply #157 on: December 21, 2014, 07:41:02 am »
Back in the day, I even used VB (you known,  installing that from zillion of 3"5 floppy) ... You want something fast with small memory footprint, try something else, like a real programming language (GFA basic? :-D)
GFA Basics? seriously?


man dont drag me to your floppy era, i'm done with it. VB today is not the same as VB 20yrs ago. even VB6 is now comparatively alot smaller footprint than say.... java w it distribution (aka runtime environment), NET4 et al the new modernization of computing theology, i cant understand why people are so care about exe footprint anymore in terrabytes era. and my quote on you dont understand what is a "language" because VB is based on "Basic Language", Basic is the language, "Visual" is just the whistle of it. you just like saying "Borland C++" is not a language because it has "Borland" in it. VB and GFA Basics are based on the same language... "Basic". dont recommend VB? dont recommend GFA ;)

few years ago I had to use it again for some obscure quick and crap proof of concept
if hate it, why use it? why dont just build "the proof of concept" right from the start in C? then you dont have to rewrite? or either.. since you build "crap proof of concept", your concept is actually crap? ;)

just for the record, to compare between floppy and "not so modern" era, vb6 somewhere in 2000... i was talking building app for windows, not DOS.



VB is "based" on basic, but far from it.

GFA was a joke, but it seems you didn't get it :-D. But it was a great think, delivered with its compiler, BTW.

Floppy era ?! Hey, it's history, you can't ignore that :-)

Can you still compile your 20 years old code ? I really doubt it, due to the fact they broke ascendant compatibility numerous times.
Take and old piece of C or C++, you'll be able to compile it without any effort. Could you with your VB code ?

I meant "memory" footprint, not "exe", that's really different. Do you think every computer are i7 based with 16Gb of memory ?! Do you think all computer are running Windows 7 ?...
When I write code, I try to make it a way that it could run a small end computers, I take care about memory footprint, speed, and so on. The points that VB "developers" ignore, or aren't aware of.

.NET is a sin (how many versions windows users have to install ?!), and just try to convince you that it a panacea.

Why not C on the first step, because the hardware that I had to control was delivered with various way to control it. And I had to check if it match our needs, very quickly, no need or time to make a clean software.
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4199
  • Country: us
Re: while loop in software
« Reply #158 on: December 21, 2014, 08:15:59 am »
BASIC was never standardized enough to be able to label any one thing as "only BASIC-like."

Quote
Take and old piece of C or C++, you'll be able to compile it without any effort.
That's pretty laughable.  Pre-posix (first published in 88, and took some time to get widely adopted) C applications had to be customized pretty heavily depending on actual target.  Your chances of compiling a 1990 Windows 3.1 C program of any complexity (even one for CLI) on a modern system "without any effort" are about zero.  (Shucks, going from gcc 2.95 to gcc 3.4, or gcc 3.4 to 4.8, for the same bare-metal cross-target, is likely to require "some" effort.)  (No, wait!  Even with modern package managers and such, trying to compile a good-sized C application from linux, on a Mac, can lead to what I usually call "dependency hell.")
 

Offline 22swg

  • Frequent Contributor
  • **
  • Posts: 274
  • Country: gb
Re: while loop in software
« Reply #159 on: December 21, 2014, 09:48:36 am »
While(on Basic) could I give PureBasic a mention ... http://www.purebasic.com/  very coder friendly..
Check your tongue, your belly and your lust. Better to enjoy someone else’s madness.
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6190
  • Country: us
Re: while loop in software
« Reply #160 on: December 21, 2014, 10:12:46 am »
While(on Basic) could I give PureBasic a mention ... http://www.purebasic.com/  very coder friendly..

Very interesting, does it have while loop?  Is it safe to use it?
 

Offline f1rmb

  • Regular Contributor
  • *
  • Posts: 180
  • Country: fr
Re: while loop in software
« Reply #161 on: December 21, 2014, 12:48:13 pm »
BASIC was never standardized enough to be able to label any one thing as "only BASIC-like."

Quote
Take and old piece of C or C++, you'll be able to compile it without any effort.
That's pretty laughable.  Pre-posix (first published in 88, and took some time to get widely adopted) C applications had to be customized pretty heavily depending on actual target.  Your chances of compiling a 1990 Windows 3.1 C program of any complexity (even one for CLI) on a modern system "without any effort" are about zero.  (Shucks, going from gcc 2.95 to gcc 3.4, or gcc 3.4 to 4.8, for the same bare-metal cross-target, is likely to require "some" effort.)  (No, wait!  Even with modern package managers and such, trying to compile a good-sized C application from linux, on a Mac, can lead to what I usually call "dependency hell.")

I think you missed the word "portability", you're talking about windows 3.1, with its nice undocumented API...

Stick to pure C/C++ (libc and friends), write some abstraction layer, and you'll have to only (re)write the platform specific sections.
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 26906
  • Country: nl
    • NCT Developments
Re: while loop in software
« Reply #162 on: December 21, 2014, 01:07:39 pm »
That is not going to work. Back in the old days every C compiler had it's own slang and own interpretation of particular rules. Remember pragmas? Just taking a piece of C code and compile it with another compiler is most likely not going to work.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline f1rmb

  • Regular Contributor
  • *
  • Posts: 180
  • Country: fr
Re: while loop in software
« Reply #163 on: December 21, 2014, 01:40:47 pm »
That is not going to work. Back in the old days every C compiler had it's own slang and own interpretation of particular rules. Remember pragmas? Just taking a piece of C code and compile it with another compiler is most likely not going to work.

Yeah #pragma :palm:
But it's preprocessor, compiler dependant.
Using specific compiler extensions is another story.
Anyway, I couldn't agree with anyone claiming that VB heaven and the programming language to learn, for obvious reasons.
So, sorry to bother, but I can't stay silent when I read such kind of thing.

« Last Edit: December 21, 2014, 05:29:23 pm by f1rmb »
 

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5550
  • Country: us
Re: while loop in software
« Reply #164 on: December 21, 2014, 07:14:15 pm »
The OP doesn't specify if he is programming an MCU or some computer with more resources.

For MCUs, C is king, C++ on bigger MCUs and of course you always have assembler. There is nothing else and C++ is just a pig.

For procedural programming and repetitive tasks you need some form of while statement, you could implement it with a goto as well but it will loop either way.

MCUs are not big enough for functional programming like Erlang with high concurrency, Even using C++11 lambdas will give you a great deal of parallelism.

But functional programming is less efficient than imperative procedural, but allows a great deal of parallelization for multicore/multiprocessors or even in the virtual computing scene with nine 9's of uptime. As for memory pointers etc, Erlang for example is single assignment, you only assign a value to a variable once, so no one else can write on it, so there is no risk of competition for the same resource.

So unless we are targeting 100 core MCUs C is still king but at the moment it would be silly to get a power hungry multicore processor to replace the functionality of an MCU, I guess depending on the task at hand (computer vision, or other heavy parallel computing applications) you might need something like that.

As for blaming C as the cause of exploits, I doubt it, I don't see many servers running C, most likely is badly coded php that allows SQL injections. And that doesn't mean buffer overruns, it just means bad programming that would allow you to do a for * query.
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7799
  • Country: us
  • adieu
Re: while loop in software
« Reply #165 on: December 21, 2014, 07:18:18 pm »
As for blaming C as the cause of exploits, I doubt it, I don't see many servers running C, most likely is badly coded php that allows SQL injections. And that doesn't mean buffer overruns, it just means bad programming that would allow you to do a for * query.

PHP is a whole different class of bad... :scared:
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6190
  • Country: us
Re: while loop in software
« Reply #166 on: December 21, 2014, 07:39:46 pm »
For MCUs, C is king, C++ on bigger MCUs and of course you always have assembler. There is nothing else and C++ is just a pig.

I prefer C++ over C even for small MCUs. Some features such as namespaces static classes and references improves the program's organization and readability with virtually no additional runtime cost.

Even in the Arduino world C++ is the standard (e.g. Serial.prinln("Hello World")).
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5319
  • Country: gb
Re: while loop in software
« Reply #167 on: December 21, 2014, 08:04:22 pm »
For MCUs, C is king, C++ on bigger MCUs and of course you always have assembler. There is nothing else and C++ is just a pig.

I prefer C++ over C even for small MCUs. Some features such as namespaces static classes and references improves the program's organization and readability with virtually no additional runtime cost.

Even in the Arduino world C++ is the standard (e.g. Serial.prinln("Hello World")).

Agreed, and I speak from a pure C old fart perspective. My concern is though that others might not understand the impact of other langiage "features" as you do. Having said that, static namespaces can be dealt with by a half decent naming convention in C in the MCU world.
 

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5550
  • Country: us
Re: while loop in software
« Reply #168 on: December 21, 2014, 09:05:39 pm »
By small MCU I mean 2048 words of programming memory or less for example a PIC16 which is considered a mid range MCU by Microchip. But by today's standards I would consider it as a base core size.

But if you have 32K, then sure C++ will fit the bill, the resulting code will be 150% the C size and 3 times slower in general computing.

C++ is good for large projects but it has a lot of traps for young players. There are good C++ programmers out there, but the bad ones are the overwhelming majority. That is the reason why Linus won't allow C++ on his kernel.

Even if it's counter intuitive, C++ can produce more dangerous code than C that it's harder to spot.

That said, for the Arduino ecosystem it does make sense to use C++ because you have an object with methods that control that device, It's nicely encapsulated and you can derive classes for similar components (not sure if they do that since I never really did any Arduino coding other than some tests on the Intel Galileo).

In that aspect C++ is more versatile for a beginner, but that doesn't mean is better, more efficient or even more maintainable. If someone refers to C as a hammer, C++ is the sledge hammer chainsaw from Deadrising 3, powerful but dangerous at the same time.

And I use C++ at work and I find it very elegant, but we have good programmers and the bad ones are spotted fairly easily since we require code reviews.

 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7799
  • Country: us
  • adieu
Re: while loop in software
« Reply #169 on: December 21, 2014, 09:07:57 pm »
But if you have 32K, then sure C++ will fit the bill, the resulting code will be 150% the C size and 3 times slower in general computing.

Demonstrably false. Any decent compiler, including GCC, has no problem switching to C++ and increasing the code size by all of a couple bytes. Then you pay for what you use - things like namespaces and overloading are free.
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5550
  • Country: us
Re: while loop in software
« Reply #170 on: December 21, 2014, 09:23:25 pm »
But if you have 32K, then sure C++ will fit the bill, the resulting code will be 150% the C size and 3 times slower in general computing.

Demonstrably false. Any decent compiler, including GCC, has no problem switching to C++ and increasing the code size by all of a couple bytes. Then you pay for what you use - things like namespaces and overloading are free.

If that is all that you are going to use C++ for, then as Howardlong stated, you can use naming conventions to get the same result in C. After all that's all the name mangling does.

But if you are going to use the full feature set I stand by my assertion.
 

Offline Marco

  • Super Contributor
  • ***
  • Posts: 6720
  • Country: nl
Re: while loop in software
« Reply #171 on: December 21, 2014, 09:40:09 pm »
As for blaming C as the cause of exploits, I doubt it, I don't see many servers running C, most likely is badly coded php that allows SQL injections. And that doesn't mean buffer overruns, it just means bad programming that would allow you to do a for * query.

I did mention SQL too (or rather the SQL interfaces we keep using). It's another one of those cases of needlessly relying on programmers not to screw up ... it's a symptom of the same disease.
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5319
  • Country: gb
Re: while loop in software
« Reply #172 on: December 21, 2014, 10:13:28 pm »
By small MCU I mean 2048 words of programming memory or less for example a PIC16 which is considered a mid range MCU by Microchip. But by today's standards I would consider it as a base core size.

But if you have 32K, then sure C++ will fit the bill, the resulting code will be 150% the C size and 3 times slower in general computing.

C++ is good for large projects but it has a lot of traps for young players. There are good C++ programmers out there, but the bad ones are the overwhelming majority. That is the reason why Linus won't allow C++ on his kernel.

Even if it's counter intuitive, C++ can produce more dangerous code than C that it's harder to spot.

That said, for the Arduino ecosystem it does make sense to use C++ because you have an object with methods that control that device, It's nicely encapsulated and you can derive classes for similar components (not sure if they do that since I never really did any Arduino coding other than some tests on the Intel Galileo).

In that aspect C++ is more versatile for a beginner, but that doesn't mean is better, more efficient or even more maintainable. If someone refers to C as a hammer, C++ is the sledge hammer chainsaw from Deadrising 3, powerful but dangerous at the same time.

And I use C++ at work and I find it very elegant, but we have good programmers and the bad ones are spotted fairly easily since we require code reviews.

I can't argue with any of that!
 

Offline Rigby

  • Super Contributor
  • ***
  • Posts: 1476
  • Country: us
  • Learning, very new at this. Righteous Asshole, too
Re: while loop in software
« Reply #173 on: December 21, 2014, 10:31:29 pm »
As for blaming C as the cause of exploits, I doubt it, I don't see many servers running C, most likely is badly coded php that allows SQL injections. And that doesn't mean buffer overruns, it just means bad programming that would allow you to do a for * query.

PHP is a whole different class of bad... :scared:

Given my hatred of C, it is nothing compared to my hatred of PHP.  We finally agree on something.

For MCUs, C is king, C++ on bigger MCUs and of course you always have assembler. There is nothing else and C++ is just a pig.

I prefer C++ over C even for small MCUs. Some features such as namespaces static classes and references improves the program's organization and readability with virtually no additional runtime cost.

Even in the Arduino world C++ is the standard (e.g. Serial.prinln("Hello World")).

Arduino is an odd mix of C and C++.  I'm actually mostly OK with C++ because it's object oriented.  PHP will never curry favor from me, OO or not, due to its completely aimless method/function naming and completely random syntax.
 
 

Offline Rigby

  • Super Contributor
  • ***
  • Posts: 1476
  • Country: us
  • Learning, very new at this. Righteous Asshole, too
Re: while loop in software
« Reply #174 on: December 21, 2014, 10:43:02 pm »
Computers are supposed to aid us.  With C, the computer just gets in the way, lets you lay little traps that no one will notice for years, and almost aids developers in making mistakes.  My primary complaint about that is that NO ONE SEEMS TO CARE.  Virtually every C developer I've known, when I mention how easy common mistakes are, they respond with something like "yeah, so don't do that."  You're sitting at a computer which was partially DESIGNED to detect errors that humans are prone to make and we still rarely use them to detect errors that humans are prone to make, purely because we each have so much misplaced confidence in our own abilities. 

The result is that every new C developer makes these mistakes again and again, and we constantly hear about code that is vulnerable to buffer overflow or memcopy exploits or whatever the bug du jour is lately.

We could use the computer to aid us as C developers, yet we choose not to.  This is my complaint.  We are so full of ourselves to think if we just remember not to do a bad thing that no bad things will happen in our code.

So you are suggesting someone invents a utopian language that won't permit the programmer to make any mistakes, and yet gives the runtime performance as C? Sounds great, why don't you do it?  You'd certainly make a lot of money.

No, I'm suggesting that people not accept tradition as a good reason for anything.  There are a lot of silly mistakes that people make, and to take steps to avoid those mistakes in the future is time and effort well spent.  Yet, here we sit, with virtually the same C we had decades ago, with newbs making the same silly mistakes they made decades ago.

Again, I'm not proposing a Utopian language, I just see a lot of little things that could be easily made better, and no effort is spent on those small changes.

Here's a potential replacement for C on micros.
http://dlang.org/comparison.html
...
Yeah, but will anybody care to write a D compiler for ARM, for Atmel, for Freescale's  PowerPC (Esys) cores or even more obscure stuff (Infinion Tricore or Freescale eTPU)?
Writing/adapting a compiler for a specific core architecture is not an easy task. Optimization strategies differ, pipeline effects have to be considered and so on. Even between cores of the same family, the command set differs. There are even cores with two switchable instruction sets, dedicated SIMD or floating point engines with very specific implementations etc.
The only reason that we can develop for ARM and Atmel with freely available compilers is that C was and is of such importance that GCC was started as open source project.
Anyway, in industrial applications with safety to consider, you usually want to use a compiler which has certain certifications and guarantees to work around known errata of the supported cores.
This means though that some software vendor like BlueRiver and the likes is interested to develop that compiler for you - which they only do if there is enough demand for it.
And honestly, for the next ten years to come, the Demand for C/C++ will be much higher than for somewhat exotic languages like D or Rust or whatever.

So on a microcontroller it's not like on the PC where you can decide freely which language to choose for a project. In the end you kinda need to use C since there is simply no other (stable, robust, certified, performant) other compiler available. The only chance would be to use a higher level language or symbolic tool that creates C code which then needs to be compiled by the default C compiler. Problem is that this increases build time and makes it very hard to debug. Also chance of tool/compiler errors increases.

I don't know if someone will care to write a compiler for D for micros.  Probably not.  Is it really that much of a sin to wish for a better environment?  Fucks sake.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf