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

0 Members and 1 Guest are viewing this topic.

Offline paulie

  • Frequent Contributor
  • **
  • !
  • Posts: 849
  • Country: us
Re: while loop in software
« Reply #225 on: December 28, 2014, 07:30:54 pm »
...
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6603
  • Country: 00
Re: while loop in software
« Reply #226 on: December 28, 2014, 07:36:05 pm »
Back to the topic, while loops are dangerous:

 

Online Howardlong

  • Super Contributor
  • ***
  • Posts: 5524
  • Country: gb
Re: while loop in software
« Reply #227 on: December 28, 2014, 09:26:55 pm »
Everything here, concurrently interacting control loops with multiple entry and exit points, cats (for Dave) and frickin' lasers.

 

Offline old greggTopic starter

  • Regular Contributor
  • *
  • Posts: 130
  • Country: 00
Re: while loop in software
« Reply #228 on: December 28, 2014, 10:46:10 pm »
man I didn't expect so many pages. Looks like it was actually a good question.

thanks a lot for all the answers. I still have some pages left to read.
 

Offline Dinsdale

  • Regular Contributor
  • *
  • Posts: 77
  • Country: us
    • pretzelogic
Re: while loop in software
« Reply #229 on: December 28, 2014, 11:21:48 pm »
I actually enjoyed the diversion into some of the C specific issues that were discussed. It's too bad all that will become lost within the topic title. I didn't really intend to side-track those.
This can't be happening.
 

Offline Rigby

  • Super Contributor
  • ***
  • Posts: 1476
  • Country: us
  • Learning, very new at this. Righteous Asshole, too
Re: while loop in software
« Reply #230 on: January 04, 2015, 03:04:09 pm »
Not to resurrect the argument I started, but if there is anyone who doesn't understand what I was getting at, and WANTS TO, here's what I was trying to say, stated far better than I could have, in the first 15 minutes of this video: http://youtu.be/ca0DWaV9uNc
 

Offline mrflibble

  • Super Contributor
  • ***
  • Posts: 2051
  • Country: nl
Re: while loop in software
« Reply #231 on: January 04, 2015, 03:41:29 pm »
Thanks for that video. That laugh @07:25 is very telling and well timed. ;D
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6603
  • Country: 00
Re: while loop in software
« Reply #232 on: January 04, 2015, 04:21:30 pm »
Not to resurrect the argument I started, but if there is anyone who doesn't understand what I was getting at, and WANTS TO, here's what I was trying to say, stated far better than I could have, in the first 15 minutes of this video: http://youtu.be/ca0DWaV9uNc

That's guy is full of himself. I stopped at the 2:30 mark. But I think I know what you mean.
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6603
  • Country: 00
Re: while loop in software
« Reply #233 on: January 04, 2015, 10:14:52 pm »
He made plenty of self deprecating remarks that would suggest he was not full of himself. Starting with emphasising he was an "academic" computer scientist.

From here he seemed to be the i-am-special-and want-attention kind of high maintenance presenter that doesn't get to the point.

Anyway, I get your point that computers could do more for us and that other programming paradigms can be more productive. We are definitely not at the end of the road.
 

Offline Rigby

  • Super Contributor
  • ***
  • Posts: 1476
  • Country: us
  • Learning, very new at this. Righteous Asshole, too
Re: while loop in software
« Reply #234 on: January 05, 2015, 03:31:40 am »
He's a college professor and has found a way to make his lectures penetrate the mind.

Everyone has something annoying.  Some wear it close, some put it out there and use it, like this guy.  Whatevs.  He's a hell of a lot smarter than me, so I'll put up with it in order to learn.
 

Offline Helix70

  • Supporter
  • ****
  • Posts: 320
  • Country: au
  • VK4JNA
Re: while loop in software
« Reply #235 on: January 05, 2015, 03:57:23 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.
 

Offline c4757p

  • Super Contributor
  • ***
  • Posts: 7799
  • Country: us
  • adieu
Re: while loop in software
« Reply #236 on: January 05, 2015, 03:59:04 am »
I mentioned this already; it was summarily ignored.
No longer active here - try the IRC channel if you just can't be without me :)
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6603
  • Country: 00
Re: while loop in software
« Reply #237 on: January 05, 2015, 04:02:54 am »
He's a college professor and has found a way to make his lectures penetrate the mind.

Everyone has something annoying.  Some wear it close, some put it out there and use it, like this guy.  Whatevs.  He's a hell of a lot smarter than me, so I'll put up with it in order to learn.

No problem. He is a free man and can behave the way he likes. He doesn't owe me a thing.
 

Offline Helix70

  • Supporter
  • ****
  • Posts: 320
  • Country: au
  • VK4JNA
Re: while loop in software
« Reply #238 on: January 05, 2015, 04:55:24 am »
I mentioned this already; it was summarily ignored.

Oh, sorry. Replied before reading the whole thread. Must try and keep up to date. Consider my post a +1 then :)
 

Offline Helix70

  • Supporter
  • ****
  • Posts: 320
  • Country: au
  • VK4JNA
Re: while loop in software
« Reply #239 on: January 05, 2015, 05:12:33 am »
Let's leave it here I don't think we are getting anywhere.

But if you ever get a real job with a large corp, you might be surprised to find there are strict standards and unless you comply, your work will be rejected.

I do believe you can see the benefits and logic in adhering to a standardized style opposed to everyone exercising individual styles.

I have a real job with a huge multi national corp. Thank the stars that improvements to code reliability are encouraged by it.
 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4628
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: while loop in software
« Reply #240 on: January 05, 2015, 07:18:56 am »
I watched his video. He made some interesting points.

The pile of rubbish stacked together is, unfortunately, a real life scenario.
And of those area's that we cannot look inside, such as car or avionic software, we all think it is 100% properly designed and tested. But recent issues with certain Prius cars say otherwise. Especially of their vulnerability to be hacked.

Engineers tend to stick to what they know, and what they like*.
Especially the latter one is a serious obstacle in innovation of engineering methods.

Sticking to legacy stuff (methods/languages from the previous era) is not something what he likes much. He's right, but please read at the *.
About legacy stuff, that is what took down Apple with the Thunderstrike exploit. Go watch that, also interesting.
 

Online Howardlong

  • Super Contributor
  • ***
  • Posts: 5524
  • Country: gb
Re: while loop in software
« Reply #241 on: January 05, 2015, 11:03:49 am »
I mentioned this already; it was summarily ignored.

Not sure it was necessarily ignored, wasn't there concern that having a literal on the left and the lvalue to the right made the code less readable in that the brain just doesn't naturally work in the way that's being recommended.

Personally I'm a bit too long in the tooth to change my own way of doing things, and I'm quite capable of determining the difference between == and = , although the danger really comes when frequently switching between languages or when the programmer is a young player in C/C++. But even then, these days the compiler will spout a warning. We all pay attention to those don't we?

My preference to to have code that generates zero warnings, and that's not achieved by relaxing the warning level. I'd have thought that's a good start for anyone. The only problem is that different compilers and different versions of compilers (and header files) frequently change the emission of warning messages, so something that compiles perfectly well one day might not the next if the compiler's updated.

Regarding the video, I guess I'm a bit thick but I didn't know anything more at the end of it than at the start, partly because what was being described was no surprise, and partly because some of the nomenclature and acronyms assumed prior knowledge and were not explained, so another hour of my life gone I guess!

(My own hobbyhorse is the plethora of non-deterministic, often but not always distributed systems, and how difficult they are to test and analyse properly, both functionally but particularly non-functionally).
 

Offline westfw

  • Super Contributor
  • ***
  • Posts: 4668
  • Country: us
Re: while loop in software
« Reply #242 on: January 05, 2015, 11:22:37 pm »
Quote
if you ever get a real job with a large corp, you might be surprised to find there are strict standards
And if you get two real jobs with two large corporations, you might be surprised to find how different and mutually contradictory they are...
 

Offline Rigby

  • Super Contributor
  • ***
  • Posts: 1476
  • Country: us
  • Learning, very new at this. Righteous Asshole, too
Re: while loop in software
« Reply #243 on: January 06, 2015, 01:47:01 am »
Depends on the language, I would say in my C-hating way.  I've worked in a couple Java positions, both had nearly identical style and structure guidelines.  One place allowed no more than 30 lines of code per method, the other 35, that was the only difference.  (This would be a bizarre metric for someone who is used to purely procedural languages like C.)
 

Offline Helix70

  • Supporter
  • ****
  • Posts: 320
  • Country: au
  • VK4JNA
Re: while loop in software
« Reply #244 on: January 06, 2015, 01:59:47 am »
Depends on the language, I would say in my C-hating way.  I've worked in a couple Java positions, both had nearly identical style and structure guidelines.  One place allowed no more than 30 lines of code per method, the other 35, that was the only difference.  (This would be a bizarre metric for someone who is used to purely procedural languages like C.)
Its a bizarre metric when you are speed and resource constrained, as the processor cycle and stack overheads for function calling can cause issues. Horses for courses, there is no real correct answer IMO.
 

Online nctnico

  • Super Contributor
  • ***
  • Posts: 30351
  • Country: nl
    • NCT Developments
Re: while loop in software
« Reply #245 on: January 06, 2015, 02:44:25 am »
A good C/C++ compiler inlines short functions anyway so there is no need to do the compiler's work.
There are small lies, big lies and then there is what is on the screen of your oscilloscope.
 

Offline Rigby

  • Super Contributor
  • ***
  • Posts: 1476
  • Country: us
  • Learning, very new at this. Righteous Asshole, too
Re: while loop in software
« Reply #246 on: January 06, 2015, 04:30:00 am »
Depends on the language, I would say in my C-hating way.  I've worked in a couple Java positions, both had nearly identical style and structure guidelines.  One place allowed no more than 30 lines of code per method, the other 35, that was the only difference.  (This would be a bizarre metric for someone who is used to purely procedural languages like C.)
Its a bizarre metric when you are speed and resource constrained, as the processor cycle and stack overheads for function calling can cause issues. Horses for courses, there is no real correct answer IMO.
True, but we had (at both places) plenty of hardware to throw at those issues.

Other situations would require other rules, certainly.

There is no one answer for all, but there can be one right answer in a given situation.
 

Offline Rigby

  • Super Contributor
  • ***
  • Posts: 1476
  • Country: us
  • Learning, very new at this. Righteous Asshole, too
Re: while loop in software
« Reply #247 on: January 06, 2015, 04:33:30 am »
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.
 

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5550
  • Country: us
Re: while loop in software
« Reply #248 on: January 06, 2015, 04:48:12 am »
True, but we had (at both places) plenty of hardware to throw at those issues.

Other situations would require other rules, certainly.

There is no one answer for all, but there can be one right answer in a given situation.

True, and the answer for an OS for > 99.99% of current systems is C & C++ without those, there are no computers.

for 99.99% of that left over 0.01% like old DEC systems, but those where probably written in VAX Assembly. Old Micros well, was assembly as well. Sure they did run basic interpreters but they were written in assembly.

Edit: that leaves 0.0001% for other than C/C++ or assembly and I'm being generous because it's probably lower than 10^-12

Other compilers will rely on libraries that are most likely C or C++ so I'm not sure about the dislike.

But I agree with one thing, over 90% of the code out there is not fully tested and I'm being generous. Well... it has been tested... by the end users, but it doesn't mean any regression or code changes resulted on that testing.

So if you really distaste C or C++, turn off your system, like it or not there is no replacement yet.

« Last Edit: January 06, 2015, 04:49:55 am by miguelvp »
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6603
  • Country: 00
Re: while loop in software
« Reply #249 on: January 06, 2015, 06:44:23 am »
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.

Have you tried go?  https://golang.org/

It's suppose to be more system oriented than Java and more productive than C/C++.

I am still waiting for the right project to give it a try.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->