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

0 Members and 1 Guest are viewing this topic.

Offline Rigby

  • Super Contributor
  • ***
  • Posts: 1476
  • Country: us
  • Learning, very new at this. Righteous Asshole, too
Re: while loop in software
« Reply #100 on: December 19, 2014, 12:40:38 am »
I am not going to say that I am smarter or more talented than anyone. 

Yes, smart people use C. 

Yes, smart people avoid C.

I do know for a fact that we could make a lot of things a lot easier with automation, including software development, yet we either choose not to, or simply believe that we don't need to because we believe we are better than we really are at things.  Hubris.

 

Offline dannyf

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: while loop in software
« Reply #101 on: December 19, 2014, 12:46:41 am »
Quote
Programming languages is after all a popularity contest.

I am not so sure.

Quote
If you are a lone wolf howling at the horrors of C, then you have to ask yourself..

Why? You pick a tool for your application. It is possible that sometimes existing code base plays a role in one's decision on languages but I have to say that in my experience, that's fairly low on my priority list.
================================
https://dannyelectronics.wordpress.com/
 

Online westfw

  • Super Contributor
  • ***
  • Posts: 4192
  • Country: us
Re: while loop in software
« Reply #102 on: December 19, 2014, 03:13:53 am »
I highly recommend this MOOC about algorithms: https://www.coursera.org/course/algs4partI
(and it's follow-on "partII", as well.)

For one thing, its wonderfully taught, with great lectures, a good set of online resources, meaningful assignments, and so on.  Just from "execution" point of view, it's one of the best MOOCs I've seen.

Secondly, you'll learn about a bunch of neat algorithms, complete with some of their applications.  If you're like me and have worked in the embedded world trying to low-level code just to get the right data into and out of a chip, you probably haven't needed to implement any fancy algorithms (arguably, hardly anyone ever needs to implement fancy algorithms; if a problem space is important enough to cause fancy algorithms, then you can go out and import the relevant code from somewhere.)  Maybe something wasn't even invented (or popular) when you last took a CS class.

Thirdly, it's a fascinating meta-glimpse into how "computer science" is different from "software engineering" or "programming."  You'll gain an understanding of why there is so much enthusiasm (in certain circles) for new languages like Java.  And concepts like recursion.  The class is taught using Java, but at a very basic level where you're truly using some of the important concepts implemented by Java, rather than some package of classes that someone says are useful for a particular purpose.  If you're familiar with some other language, you shouldn't have any trouble converting the Java examples.  (The class/book has previously used other languages, so the instructor has things really distilled down to core concepts.  Also, there's a fair amount of discussion of Java internals (particularly WRT size of data objects) and limitations that I found really useful.)
 

Offline hamster_nz

  • Super Contributor
  • ***
  • Posts: 2803
  • Country: nz
Re: while loop in software
« Reply #103 on: December 19, 2014, 03:54:15 am »
Quote
Programming languages is after all a popularity contest.

I am not so sure.

Why are you not so sure? I've seen too many things fall in and out of fashion to say that one tool is superior to the others - things like Java, Javascript, Perl, PHP, Python, COBOL, BASIC, Pascal, Go, Delphi, Smalltalk, Fortran, LISP, PL/1, C++, Visual Basic, C#,  PL/SQL, SQL Forms, AWK/sed and so on, endless GUI programming environments, endless different IDEs, different design methodologies JSP, three-tiered applications, data driven development, design patterns, functional programming languages, Agile, blah, blah, blah,,

Some of the languages bring new things to the table, and others take them away. None of them solve the core problem that programming is hard, and any programming language that is expressive enough to be useful makes it easy to write buggy code.

Just look through any programmers bookshelf who is older than 40 - the only books of value are anything on algorithms and the K+R ANSI C book. For all the others, at the time they were purchased they were considered important to spend real money, now they are junk.

In general it isn't the tools you use that determine results, it is the people who use them. It is a fact of life that 50% of projects will get sub-average results, and a great team with only shoddy tool-sets will outshine a shoddy team with the best tools.

So if I need something done, and it is appropriate, give me a good C programmer and let him use it's unbounded arrays, pointers, and while() loops. Heck, they can even use "goto"s for trapping errors if they must.

Just don't give me an sub-average programmer and demand that they use a tool-set that is a language designer's wet dream, believing it will give spectacular results. It wont.
Gaze not into the abyss, lest you become recognized as an abyss domain expert, and they expect you keep gazing into the damn thing.
 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4064
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: while loop in software
« Reply #104 on: December 19, 2014, 06:24:28 am »
Fascinating how a general question about the use cases of while loops evolves into a philosophical debate on programming languages.

Are we off-topic already?
 

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5550
  • Country: us
Re: while loop in software
« Reply #105 on: December 19, 2014, 06:51:42 am »
I guess the question is, can you create a program that totally avoids while loops and is still readable and maintainable?
Taking in consideration that an unconditional goto looping back is the same thing as a while (1) or for(;;) statement.

Unless you are talking about functional languages, but they still have while loops to read their messages process them and spit them out, even if there is no concurrency it all loops.

Event driven databases? maybe they don't need loops but something is monitoring the interrupts or whatever triggers the events and that's probably looping.

Why would the terms of "main loop" or "event loop" would be used if it doesn't imply you need such loop?

But yeah, you can write programs that are a one off, but if you want to call that program again, something is looping.

I think that most (over 99.9%) of the programs loop, for/while/goto same difference.
« Last Edit: December 19, 2014, 07:39:12 am by miguelvp »
 

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11518
  • Country: my
  • reassessing directives...
Re: while loop in software
« Reply #106 on: December 19, 2014, 07:37:01 am »
My stance is that things COULD be better, but we ignore that shit and dont implement better language features because that shit isn't C
it isnt particularly about C or else. talking about say... inherent/built in boundary check in a language is a root thing when trying to inventing one particularly new language. and then further it will related to or mess with hardware/cpu core design. software boundary check is expensive (in real software), even with hardware i guess, we are talking PC level intel real gigas i-core cpu and ram here, let alone embedded world. so its decided not to have boundary check, they left it to human the programmer to handle it, who decided that? those sharp people up there whose job designing a language or laying out specifications, and the majority in the clan below ofcourse.. i guess. another way to put it, is the freedom to do or not to do. once the boundary check is stuck in a language, nothing you can do about it, even a simple homebrew memset or memzero will take so long. like an automatic car without manual overide knob try running jungle track or curvy/difficult road uphill i hate that. for the minority of the clan who think no boundary check is an abomination, they have the right to use more modern language such as "managed" type of language, go for C# or VB#, it has wonderful automation, thats the improvement made for the problem, thats modern. i dont say we should not improve, i only saying, is the direction of your improvement right? if people think a new language should be invented, then go for it but dont impose other people from exercising their freedom in software development. heck i believe even the modern "managed" language are built on top of "unmanaged" language such as c/c++. think why? the people who decided that are not muggles.
« Last Edit: December 19, 2014, 07:42:09 am by Mechatrommer »
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 mikerj

  • Super Contributor
  • ***
  • Posts: 3231
  • Country: gb
Re: while loop in software
« Reply #107 on: December 19, 2014, 09:52:10 pm »
I want to knock the hubris out of every C developer that thinks that C is all that is needed, or is all that is useful.

Why have you set out on this strange and lonely mission?  Quite honestly it sounds like you've burnt your fingers trying to develop something in C and have somehow decided it was the fault of the language.
 

Offline nctnico

  • Super Contributor
  • ***
  • Posts: 26682
  • Country: nl
    • NCT Developments
Re: while loop in software
« Reply #108 on: December 19, 2014, 10:08:53 pm »
I agree with Rigby and there are alternatives like PL/M and ADA which take care of a lot of potential problems with pointers. A modern choice would be Lua. With larger amounts of RAM and flash the amount of software which deals with hardware is only a fraction of the entire firmware. It makes perfect sense to use a higher level language for the logic & data processing part of the firmware if that programming language helps to avoid the many pitfalls C offers.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline Marco

  • Super Contributor
  • ***
  • Posts: 6686
  • Country: nl
Re: while loop in software
« Reply #109 on: December 19, 2014, 10:30:40 pm »
Why have you set out on this strange and lonely mission?  Quite honestly it sounds like you've burnt your fingers trying to develop something in C and have somehow decided it was the fault of the language.

Buffer overflows are the fault of the language ... unbounded pointers should be the exception, not the rule. If we had started using run time bound checking (and languages which make it awkward to use unbounded pointers) when we started to realize how easy bugs and exploits were created by not doing so then performance wouldn't even have been an issue at this point, ISA would have included fast instructions for it.

The continued use of C in internet facing systems is negligent (SQL too for that matter).
 

Offline Rigby

  • Super Contributor
  • ***
  • Posts: 1476
  • Country: us
  • Learning, very new at this. Righteous Asshole, too
Re: while loop in software
« Reply #110 on: December 19, 2014, 10:43:50 pm »
I want to knock the hubris out of every C developer that thinks that C is all that is needed, or is all that is useful.

Why have you set out on this strange and lonely mission?  Quite honestly it sounds like you've burnt your fingers trying to develop something in C and have somehow decided it was the fault of the language.

I've developed in C plenty.  I have lots of code in production in various places and on various platforms, from microcontrollers to PC applications.

My distaste of C derives purely from use of and experience with C and in comparing C to other languages.

I see what computers can do, and I see how C is very much unchanged in so many ways after over 40 years.  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.
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7799
  • Country: us
  • adieu
Re: while loop in software
« Reply #111 on: December 19, 2014, 10:49:54 pm »
Some languages are more "high-level" than others - they abstract the hardware more. C does fewer things by itself, making its code closer to what the machine is directly capable of. Why do we have to bicker about whether we'd rather it do more or less for us? That doesn't make it a poor language, that just makes it closer to the "metal" - and sure, if you don't need to work that close to the metal, don't. That doesn't mean there's something wrong with tools that are intended for that sort of work.

Instead of bitching about how the hammer that is C is just terrible at driving screws, why not restrict it to nail-driving and use something else for the screws?
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline Rigby

  • Super Contributor
  • ***
  • Posts: 1476
  • Country: us
  • Learning, very new at this. Righteous Asshole, too
Re: while loop in software
« Reply #112 on: December 20, 2014, 12:05:43 am »
Because C is not a good hammer or a good screwdriver.  C is a kit that aids one in the creation of stupid mistakes and security vulnerabilities, and everyone is OK with that.

Ya know what?  Clearly I'm wrong.  Clearly a language that aids the developer in the production of shit code is the right thing.  Ok.  I'll just drop out of this conversation and let you all have your C circle jerk.
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7799
  • Country: us
  • adieu
Re: while loop in software
« Reply #113 on: December 20, 2014, 12:10:18 am »
C is a kit that aids one in the creation of stupid mistakes and security vulnerabilities when used for the wrong tasks - fixed that for you.

I'll just drop out of this conversation and let you all have your C circle jerk.

Ooh, a C circle jerk - sounds like fun! Where?
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline 0xdeadbeef

  • Super Contributor
  • ***
  • Posts: 1570
  • Country: de
Re: while loop in software
« Reply #114 on: December 20, 2014, 12:29:55 am »
Performance is one point, but what was somewhat ignored here is that languages with pointers are actually needed to implement low level stuff like writing to peripheral registers. And sometimes even C is not low level enough and you'll need inline assembly just to write to a special function register or to use a specific opcode (like count leading zeroes and stuff like this).
Still, even this is only possible if the compilers allows passing of register/automatic variables between "high level" (i.e. C) and assembly language.

Also, when talking about implementing an operating system, priority manipulation, context switching and so, you'll need at least a language like C that allows low level access.

IMHO, there will alway be a place for C and assembly for low level and time critical stuff.
Personally, I do all my PC stuff in Java (if I want it platform independent) or C# (if I need some Windows specific libraries), but all microcontroller stuff in C.
Trying is the first step towards failure - Homer J. Simpson
 

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11518
  • Country: my
  • reassessing directives...
Re: while loop in software
« Reply #115 on: December 20, 2014, 01:23:35 am »
when people kill someone with a hammer... blame the hammer :D

My primary complaint about that is that NO ONE SEEMS TO CARE.
i guess its not that they not or havent care, but if they do care, it will create another problem for them and the humanity. as i said, let your voice reach up there in the ieee comitte. if they decide that your decision is wiser, i believe they'll listen.
« Last Edit: December 20, 2014, 01:32:06 am by Mechatrommer »
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 f1rmb

  • Regular Contributor
  • *
  • Posts: 180
  • Country: fr
Re: while loop in software
« Reply #116 on: December 20, 2014, 01:41:01 am »
It's really funny to read that some people hate C because it's too low level, and developer have to take care of everything with it.

Errrr, isn't the job of the developer to do that?! Isn't the intrinsic part of the job?. Yeah, you have to take care where you move your pointers, your memory allocations, and stuff like that, wow, what a deal.

C is quite low level, permissive, but it's damn powerful and light, and it's the way it has been designed.

It's fourty years old, yeah, and still used and loved, ask yourself why (I won't bet anything on these <whatever letter># crap, or new fashion language, will survive 20).

C, C++ and ASM will survive us, all of us.

---
Daniel
 

Offline Rigby

  • Super Contributor
  • ***
  • Posts: 1476
  • Country: us
  • Learning, very new at this. Righteous Asshole, too
Re: while loop in software
« Reply #117 on: December 20, 2014, 01:48:00 am »
I don't hate C.  I hate that C devs flatly reject advances in software development. 

I also hate behavior just like what you just typed up.  Dismissal of my point of solely because it does not match your own.
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7799
  • Country: us
  • adieu
Re: while loop in software
« Reply #118 on: December 20, 2014, 01:50:23 am »
I don't hate C.

Because C is not a good hammer or a good screwdriver.  C is a kit that aids one in the creation of stupid mistakes and security vulnerabilities, and everyone is OK with that.

... a language that aids the developer in the production of shit code ...

My distaste of C derives purely from use of and experience with C and in comparing C to other languages.
...
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.

Presented without comment.
« Last Edit: December 20, 2014, 01:54:10 am by c4757p »
No longer active here - try the IRC channel if you just can't be without me :)
 

Online Mechatrommer

  • Super Contributor
  • ***
  • Posts: 11518
  • Country: my
  • reassessing directives...
Re: while loop in software
« Reply #119 on: December 20, 2014, 01:58:56 am »
go for visual basic 6 my friend... it has array bound check in every compile option, your problem solved! its been 14 years old and i'm still using it, with 99.99999% array bound check turned OFF ;)
a boundary check in each 2 billions iteration of memory access in my dumb and stupid example earlier is a epic!
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 suicidaleggroll

  • Super Contributor
  • ***
  • Posts: 1453
  • Country: us
Re: while loop in software
« Reply #120 on: December 20, 2014, 02:01:02 am »
There are arguments for both paradigms.

Most high level languages have all kinds of error checking built in.  They're big, they require gobs of resources, and they're slow (I'm looking at you IDL, Matlab, Python, etc.).  They're like a programmer's sandbox.  You can have fun, you can play around, but you have to stay inside the walls or the school teacher scolds you.  You're allowed to do what the language allows you to do, no more.  This makes the language safe.  Any out of bounds array references will throw an error, any loop errors will throw an error.  Any dangerous errors of any kind will throw an error.  They're great for prototyping when you don't want to bring down the machine, but as I said before, they're big, they require gobs of resources, they're slow, and you're only allowed to do what the language allows you to do.

Low level languages like C or Assembly take the other approach.  They assume you know what you're doing and get the hell out of the way.  This makes them fast...very fast, and it also makes them insanely flexible and powerful, BUT it makes them vulnerable.  If you screw up, you can do all sorts of damage.

High level languages are great when resources aren't a problem, execution speed is not a problem, and you're only doing "sandbox" activities.  When you get outside of that goldilocks regime, you need to move to a low level language that gets out of the way and lets you do what you need to do.  Of course when you're in this realm, any mistakes are on you, the language won't hold your hand and babysit you through the debugging process.  That's not a fault of the language, it's an inherent byproduct of the types of tools you need to use when working in this domain.

That doesn't mean C is crap and needs to die, it just means that you should only use C when it's the right tool for the job, which it often is...
 

Offline suicidaleggroll

  • Super Contributor
  • ***
  • Posts: 1453
  • Country: us
Re: while loop in software
« Reply #121 on: December 20, 2014, 02:02:24 am »
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.
 

Online westfw

  • Super Contributor
  • ***
  • Posts: 4192
  • Country: us
Re: while loop in software
« Reply #122 on: December 20, 2014, 02:05:11 am »
I like C a lot.  It was one of the first languages to reject the idea that a large runtime library should be part of the language definition, leading relatively directly to a degree of portability across Architectures and Environments that has seldom been equaled (and I think that that is largely responsible for its success.) (and at a time when other languages (Looking at PL/1 and Ada) were including HUGE runtimes that were incompatible with the language definition.  (It always particularly annoyed me that the Pascal built-in functions did things that were not permitted of user functions (variable number of arguments in Print(), for example.))

I do wish that they had included strings as part of the language, though.  There's nothing wrong with pointers in general, but having to use them ALL THE TIME to deal with something as common as strings is both annoying and error-prone.
 

Offline Marco

  • Super Contributor
  • ***
  • Posts: 6686
  • Country: nl
Re: while loop in software
« Reply #123 on: December 20, 2014, 02:05:50 am »
More likely than not C is why Sony Pictures is being destroyed. More likely than not C is why a German steel mill has a load of scrap on it's hands where they once had expensive machinery. C is a weapon of mass destruction.
 

Offline f1rmb

  • Regular Contributor
  • *
  • Posts: 180
  • Country: fr
Re: while loop in software
« Reply #124 on: December 20, 2014, 02:08:57 am »
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 :palm:

---
Daniel
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf