* AW: Translating an embedded C algorithm [not found] <E473CA319B6D514981A06AE6742A1FD82B067D@GLDMS10607.goldlnk.rootlnka.net> @ 2007-01-17 7:07 ` Grein, Christoph (Fa. ESG) 2007-01-17 10:26 ` Ludovic Brenta 0 siblings, 1 reply; 16+ messages in thread From: Grein, Christoph (Fa. ESG) @ 2007-01-17 7:07 UTC (permalink / raw) To: comp.lang.ada No, there are again some mistakes: ... > --| Temperature in ºC x 10. INVALID_TEMPERATURE if out of range. Incorrect: There's no INVALID_TEMPERATURE ... > InterpolationDistance := (Adc_Count - MINIMUM_ADC_COUNT) mod (SPACING - 1); Wrong again: mod Spacing But: As others have pointed out, a mere translation of C code is not Ada. You would use constrained types rather than Integer and other Ada idioms (put it in a package, add context clauses, use different integer types for different abstractions etc...). ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: AW: Translating an embedded C algorithm 2007-01-17 7:07 ` AW: Translating an embedded C algorithm Grein, Christoph (Fa. ESG) @ 2007-01-17 10:26 ` Ludovic Brenta 2007-01-17 16:44 ` Markus E Leypold [not found] ` <1%trh.15628$X72.889@newsread3.news.pas.earthlink.net> 0 siblings, 2 replies; 16+ messages in thread From: Ludovic Brenta @ 2007-01-17 10:26 UTC (permalink / raw) Grein, Christoph (Fa. ESG) writes: > No, there are again some mistakes: > > ... >> --| Temperature in ºC x 10. INVALID_TEMPERATURE if out of range. > > Incorrect: There's no INVALID_TEMPERATURE > > ... >> InterpolationDistance := (Adc_Count - MINIMUM_ADC_COUNT) mod (SPACING - 1); > > Wrong again: mod Spacing > > But: As others have pointed out, a mere translation of C code is not > Ada. You would use constrained types rather than Integer and other > Ada idioms (put it in a package, add context clauses, use different > integer types for different abstractions etc...). Right, and there would be no need for a silly INVALID_TEMPERATURE. What *is* an invalid temperature anyway? One that needs crutches? One that is excused from military service? And why would you ever return an invalid temperature to your caller? etc. etc. -- Ludovic Brenta. ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: AW: Translating an embedded C algorithm 2007-01-17 10:26 ` Ludovic Brenta @ 2007-01-17 16:44 ` Markus E Leypold 2007-01-18 8:49 ` Ludovic Brenta [not found] ` <1%trh.15628$X72.889@newsread3.news.pas.earthlink.net> 1 sibling, 1 reply; 16+ messages in thread From: Markus E Leypold @ 2007-01-17 16:44 UTC (permalink / raw) Ludovic Brenta <ludovic@ludovic-brenta.org> writes: > Grein, Christoph (Fa. ESG) writes: >> No, there are again some mistakes: >> >> ... >>> --| Temperature in �C x 10. INVALID_TEMPERATURE if out of range. >> >> Incorrect: There's no INVALID_TEMPERATURE >> >> ... >>> InterpolationDistance := (Adc_Count - MINIMUM_ADC_COUNT) mod (SPACING - 1); >> >> Wrong again: mod Spacing >> >> But: As others have pointed out, a mere translation of C code is not >> Ada. You would use constrained types rather than Integer and other >> Ada idioms (put it in a package, add context clauses, use different >> integer types for different abstractions etc...). > > Right, and there would be no need for a silly INVALID_TEMPERATURE. > What *is* an invalid temperature anyway? One that needs crutches? > One that is excused from military service? And why would you ever > return an invalid temperature to your caller? etc. etc. | >> --| Temperature in �C x 10. INVALID_TEMPERATURE if out of range. If the sensor is out of order or the temperature leaves the range where it functions properly? :-). Regards -- Markus ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: AW: Translating an embedded C algorithm 2007-01-17 16:44 ` Markus E Leypold @ 2007-01-18 8:49 ` Ludovic Brenta 2007-01-18 9:53 ` Markus E Leypold 2007-01-19 9:33 ` Stephen Leake 0 siblings, 2 replies; 16+ messages in thread From: Ludovic Brenta @ 2007-01-18 8:49 UTC (permalink / raw) Markus E Leypold writes: > Ludovic Brenta <ludovic@ludovic-brenta.org> writes: >> Right, and there would be no need for a silly INVALID_TEMPERATURE. >> What *is* an invalid temperature anyway? One that needs crutches? >> One that is excused from military service? And why would you ever >> return an invalid temperature to your caller? etc. etc. > > | >> --| Temperature in ºC x 10. INVALID_TEMPERATURE if out of range. > > If the sensor is out of order or the temperature leaves the range > where it functions properly? > > :-). My point it this: if the sensor is out of order, then there is no known temperature; not a known "invalid" temperature. The proper way to handle that in Ada is with an exception, not a special value of type Degrees_C. -- Ludovic Brenta. ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: AW: Translating an embedded C algorithm 2007-01-18 8:49 ` Ludovic Brenta @ 2007-01-18 9:53 ` Markus E Leypold 2007-01-19 9:33 ` Stephen Leake 1 sibling, 0 replies; 16+ messages in thread From: Markus E Leypold @ 2007-01-18 9:53 UTC (permalink / raw) Ludovic Brenta <ludovic@ludovic-brenta.org> writes: > Markus E Leypold writes: >> Ludovic Brenta <ludovic@ludovic-brenta.org> writes: >>> Right, and there would be no need for a silly INVALID_TEMPERATURE. >>> What *is* an invalid temperature anyway? One that needs crutches? >>> One that is excused from military service? And why would you ever >>> return an invalid temperature to your caller? etc. etc. >> >> | >> --| Temperature in �C x 10. INVALID_TEMPERATURE if out of range. >> >> If the sensor is out of order or the temperature leaves the range >> where it functions properly? >> >> :-). > > My point it this: if the sensor is out of order, then there is no > known temperature; not a known "invalid" temperature. The proper way Yep, certainly. Actually 'temperature' is the wrong description for this type. It's actually "the result of reading the temperature sensor" which is a union type between a finite temperature range and the "invalid result". > to handle that in Ada is with an exception, That depends on how "exceptional" that event is. If it is a hardware failure an exception would perhaps be better, but if it just means "temperature went out of range" (or better "too high") dependend on what kind of apparatus we have here, it might be better to handle that as a special case (like: a very high temperature we don't don't knoe exactly). A (very primitive and perhaps incomplete) example: A temperature sensor for some kind of nuclear or chemical process. If the the temperature becomes > t2 we'd want the emergency cooling to be activated. We'd also want this if the it becomes > t3, the temperature where the sensor stops to work properly (which is higher than t2, but where we still know that the temperature is too high). In that case an exception or even an emergency shutdown of the controlling unit would be wrong. > not a special value of type Degrees_C. Agreed. Degrees_C is misleading. What about Sensor_Result? Regards -- Markus ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: AW: Translating an embedded C algorithm 2007-01-18 8:49 ` Ludovic Brenta 2007-01-18 9:53 ` Markus E Leypold @ 2007-01-19 9:33 ` Stephen Leake 2007-01-19 19:23 ` Cesar Rabak 1 sibling, 1 reply; 16+ messages in thread From: Stephen Leake @ 2007-01-19 9:33 UTC (permalink / raw) Ludovic Brenta <ludovic@ludovic-brenta.org> writes: > Markus E Leypold writes: >> Ludovic Brenta <ludovic@ludovic-brenta.org> writes: >>> Right, and there would be no need for a silly INVALID_TEMPERATURE. >>> What *is* an invalid temperature anyway? One that needs crutches? >>> One that is excused from military service? And why would you ever >>> return an invalid temperature to your caller? etc. etc. >> >> | >> --| Temperature in �C x 10. INVALID_TEMPERATURE if out of range. >> >> If the sensor is out of order or the temperature leaves the range >> where it functions properly? >> >> :-). > > My point it this: if the sensor is out of order, then there is no > known temperature; not a known "invalid" temperature. The proper way > to handle that in Ada is with an exception, not a special value of > type Degrees_C. In a real-time system that is tolerant of hardware failures, every hardware measurement should be accompanied by some sort of quality flag. In this case, a boolean would do; Temperature_Valid. The point is that when hardware failures are expected, they are best handled by normal data, not exceptions. Using a special value of Temperature to represent hardware failure is an example of in-band signaling; using a separate quality flag is out-of-band signaling. Out-of-band is a bit more complicated, but much more robust. This example program is far too small to show the crucial differences between C and Ada. -- -- Stephe ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: AW: Translating an embedded C algorithm 2007-01-19 9:33 ` Stephen Leake @ 2007-01-19 19:23 ` Cesar Rabak 2007-01-19 20:27 ` Robert A Duff 0 siblings, 1 reply; 16+ messages in thread From: Cesar Rabak @ 2007-01-19 19:23 UTC (permalink / raw) Stephen Leake escreveu: > Ludovic Brenta <ludovic@ludovic-brenta.org> writes: [snipped] > > This example program is far too small to show the crucial differences > between C and Ada. > I think you summarized very well the whole issue here! ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: AW: Translating an embedded C algorithm 2007-01-19 19:23 ` Cesar Rabak @ 2007-01-19 20:27 ` Robert A Duff 2007-01-19 23:15 ` Cesar Rabak ` (2 more replies) 0 siblings, 3 replies; 16+ messages in thread From: Robert A Duff @ 2007-01-19 20:27 UTC (permalink / raw) Cesar Rabak <csrabak@yahoo.com.br> writes: > Stephen Leake escreveu: >> Ludovic Brenta <ludovic@ludovic-brenta.org> writes: > [snipped] >> This example program is far too small to show the crucial differences >> between C and Ada. >> > > I think you summarized very well the whole issue here! But the OP didn't ask anybody to "show the crucial differences between C and Ada"; he asked for a simple half-page C function to be translated into Ada, which is a perfectly reasonable request. I started to do it myself, but others have answered that question, so he got more-or-less what he asked for. He also got "we can't translate simple C into simple Ada -- we need to create a hugely complicated mess", and he also got "you dope, how dare you ask about Ada when you don't already know Ada". Sigh. - Bob ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: AW: Translating an embedded C algorithm 2007-01-19 20:27 ` Robert A Duff @ 2007-01-19 23:15 ` Cesar Rabak 2007-01-20 9:54 ` Dmitry A. Kazakov 2007-01-20 21:03 ` AW: " Jeffrey Carter 2 siblings, 0 replies; 16+ messages in thread From: Cesar Rabak @ 2007-01-19 23:15 UTC (permalink / raw) Robert A Duff escreveu: > Cesar Rabak <csrabak@yahoo.com.br> writes: > >> Stephen Leake escreveu: >>> Ludovic Brenta <ludovic@ludovic-brenta.org> writes: >> [snipped] >>> This example program is far too small to show the crucial differences >>> between C and Ada. >>> >> I think you summarized very well the whole issue here! > > But the OP didn't ask anybody to "show the crucial differences between C > and Ada"; he asked for a simple half-page C function to be translated > into Ada, which is a perfectly reasonable request. Yes. > I started to do it > myself, but others have answered that question, so he got more-or-less > what he asked for. OK. I believe he got a handful set of examples. > He also got "we can't translate simple C into simple > Ada -- we need to create a hugely complicated mess", and he also got > "you dope, how dare you ask about Ada when you don't already know Ada". While I have to agree that hearing from the aisles our internal discussion could be described like that, I think we have to think about the other side. A direct translation of a that half page (C language) function, would convey very little about Ada, and perhaps lead to a conclusion that is just a C (or rather Pascal) like language with a "weird syntax" (pundits could step and say all other things we're used, as being verbose, etc.). So a reasonable (I agree that with less ado) remark that Ada language to be used in its full potential would include more code (like was shown in the thread already) and a clear and better explanation of the advantages of it would have been better advertising of Ada. > Sigh. Relieved? :-) ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: Translating an embedded C algorithm 2007-01-19 20:27 ` Robert A Duff 2007-01-19 23:15 ` Cesar Rabak @ 2007-01-20 9:54 ` Dmitry A. Kazakov 2007-01-20 21:03 ` AW: " Jeffrey Carter 2 siblings, 0 replies; 16+ messages in thread From: Dmitry A. Kazakov @ 2007-01-20 9:54 UTC (permalink / raw) On Fri, 19 Jan 2007 15:27:58 -0500, Robert A Duff wrote: > But the OP didn't ask anybody to "show the crucial differences between C > and Ada"; he asked for a simple half-page C function to be translated > into Ada, which is a perfectly reasonable request. Sure, but that piece of code was intended to demonstrate a solution of some problem by means of a programming language. > He also got "we can't translate simple C into simple > Ada -- we need to create a hugely complicated mess", For good or bad, but this one of key features of Ada as a programming language, I think. My theory is that Ada has a much finer and precise definition of program semantics. It is a deeply layered "mess" of "what-ifs," which normal C programmers would just promptly ignore. In Ada I never know if there couldn't be a better way, or whether there were a hidden gotcha in some rare obscure pathological case. This is not good. In C++ I just don't care, I know for sure, there are lots. My attitude is different. This is also not good, but has huge psychological (=>marketing) advantages over Ada. > and he also got > "you dope, how dare you ask about Ada when you don't already know Ada". I don't justify this, but I understand the reasons, cultural reasons. I tolerate much worse C++ code from myself and others, than I could in the case of an "equivalent" Ada code. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: AW: Translating an embedded C algorithm 2007-01-19 20:27 ` Robert A Duff 2007-01-19 23:15 ` Cesar Rabak 2007-01-20 9:54 ` Dmitry A. Kazakov @ 2007-01-20 21:03 ` Jeffrey Carter 2007-01-20 21:38 ` Robert A Duff 2 siblings, 1 reply; 16+ messages in thread From: Jeffrey Carter @ 2007-01-20 21:03 UTC (permalink / raw) Robert A Duff wrote: > "you dope, how dare you ask about Ada when you don't already know Ada". No. He got, "Are you qualified to write a book on real-time embedded SW development when you only know C?" ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: AW: Translating an embedded C algorithm 2007-01-20 21:03 ` AW: " Jeffrey Carter @ 2007-01-20 21:38 ` Robert A Duff 2007-01-22 2:30 ` Jeffrey Carter 0 siblings, 1 reply; 16+ messages in thread From: Robert A Duff @ 2007-01-20 21:38 UTC (permalink / raw) Jeffrey Carter <spam.jrcarter.not@spam.acm.not.org> writes: > Robert A Duff wrote: >> "you dope, how dare you ask about Ada when you don't already know Ada". > > No. He got, "Are you qualified to write a book on real-time embedded SW > development when you only know C?" OK, I admit it -- I exaggerated a little. ;-) Still, IMHO a gentler approach would be more likely to get him to (1) learn something about Ada and/or (2) put a small Ada example in his book, thus tempting others to learn about it. I'm sure you didn't mean to attack the guy, but questioning someones competence could come across that way, don't you think? - Bob ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: AW: Translating an embedded C algorithm 2007-01-20 21:38 ` Robert A Duff @ 2007-01-22 2:30 ` Jeffrey Carter 2007-01-23 7:43 ` Stephen Leake 0 siblings, 1 reply; 16+ messages in thread From: Jeffrey Carter @ 2007-01-22 2:30 UTC (permalink / raw) Robert A Duff wrote: > > I'm sure you didn't mean to attack the guy, but questioning someones > competence could come across that way, don't you think? I'm not a very good judge of such things. Obviously a lot of people thought so. In my experience, the vast majority of people involved in SW development are not qualified to design SW, much less write books about it. I'm marginally qualified, and I'm familiar with a number of people who are better qualified, but I'm also familiar with large numbers of people who aren't qualified. I think it's very important to SW and the world that this situation be improved, so I tend to bring it up when it seems important. I'm not sure what this has to do with my lack of social skills. ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: AW: Translating an embedded C algorithm 2007-01-22 2:30 ` Jeffrey Carter @ 2007-01-23 7:43 ` Stephen Leake 2007-01-23 19:34 ` Jeffrey R. Carter 0 siblings, 1 reply; 16+ messages in thread From: Stephen Leake @ 2007-01-23 7:43 UTC (permalink / raw) Jeffrey Carter <spam.jrcarter.not@spam.acm.not.org> writes: > Robert A Duff wrote: >> I'm sure you didn't mean to attack the guy, but questioning someones >> competence could come across that way, don't you think? > > I'm not a very good judge of such things. Obviously a lot of people > thought so. > > In my experience, the vast majority of people involved in SW > development are not qualified to design SW, much less write books > about it. I'm marginally qualified, and I'm familiar with a number of > people who are better qualified, but I'm also familiar with large > numbers of people who aren't qualified. I think it's very important to > SW and the world that this situation be improved, so I tend to bring > it up when it seems important. > > I'm not sure what this has to do with my lack of social skills. Since he is _already_ writing a book, clearly he believes he's qualified. So a statement "you are not qualified" will simply be rejected. As I recall, your statement was phrased as a question, something like "how can you think you are qualified when you don't know Ada". That implies both that he _isn't_ qualified, and that he doesn't know what _qualified_ means in the first place. Both messages will simply be rejected; he will assume you are just a crank, since you don't know him personally. Criticizing people effectively is a social skill. I'm a blue-blood physics nerd, but a few things have rubbed off on me from my social-worker wife :). Generally, criticism at this level will only be accepted from someone you know, or someone you have a formal relationship with; an editor, or an official reviewer. -- -- Stephe ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: AW: Translating an embedded C algorithm 2007-01-23 7:43 ` Stephen Leake @ 2007-01-23 19:34 ` Jeffrey R. Carter 0 siblings, 0 replies; 16+ messages in thread From: Jeffrey R. Carter @ 2007-01-23 19:34 UTC (permalink / raw) Stephen Leake wrote: > > As I recall, your statement was phrased as a question, something like > "how can you think you are qualified when you don't know Ada". That > implies both that he _isn't_ qualified, and that he doesn't know what > _qualified_ means in the first place. Both messages will simply be > rejected; he will assume you are just a crank, since you don't know > him personally. Actually, it was a statement about myself, along the lines of "I wonder if someone who only knows C is qualified." ^ permalink raw reply [flat|nested] 16+ messages in thread
[parent not found: <1%trh.15628$X72.889@newsread3.news.pas.earthlink.net>]
* Re: AW: Translating an embedded C algorithm [not found] ` <1%trh.15628$X72.889@newsread3.news.pas.earthlink.net> @ 2007-01-17 18:44 ` Niklas Holsti 0 siblings, 0 replies; 16+ messages in thread From: Niklas Holsti @ 2007-01-17 18:44 UTC (permalink / raw) Dennis Lee Bieber wrote: > On Wed, 17 Jan 2007 11:26:32 +0100, Ludovic Brenta > <ludovic@ludovic-brenta.org> declaimed the following in comp.lang.ada: > > >>Right, and there would be no need for a silly INVALID_TEMPERATURE. >>What *is* an invalid temperature anyway? One that needs crutches? > > > Well... anything that comes out as less than 0deg Kelvin <G> Maybe not -- see, for example, http://math.ucr.edu/home/baez/physics/ParticleAndNuclear/neg_temperature.html <quote> Questions: What is negative temperature? Can you really make a system which has a temperature below absolute zero? Can you even give any useful meaning to the expression 'negative absolute temperature'? Answer: Absolutely. :-) Under certain conditions, a closed system can be described by a negative temperature, and, surprisingly, be hotter than the same system at any positive temperature. This article describes how it all works. </quote> -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ . ^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2007-01-23 19:34 UTC | newest] Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <E473CA319B6D514981A06AE6742A1FD82B067D@GLDMS10607.goldlnk.rootlnka.net> 2007-01-17 7:07 ` AW: Translating an embedded C algorithm Grein, Christoph (Fa. ESG) 2007-01-17 10:26 ` Ludovic Brenta 2007-01-17 16:44 ` Markus E Leypold 2007-01-18 8:49 ` Ludovic Brenta 2007-01-18 9:53 ` Markus E Leypold 2007-01-19 9:33 ` Stephen Leake 2007-01-19 19:23 ` Cesar Rabak 2007-01-19 20:27 ` Robert A Duff 2007-01-19 23:15 ` Cesar Rabak 2007-01-20 9:54 ` Dmitry A. Kazakov 2007-01-20 21:03 ` AW: " Jeffrey Carter 2007-01-20 21:38 ` Robert A Duff 2007-01-22 2:30 ` Jeffrey Carter 2007-01-23 7:43 ` Stephen Leake 2007-01-23 19:34 ` Jeffrey R. Carter [not found] ` <1%trh.15628$X72.889@newsread3.news.pas.earthlink.net> 2007-01-17 18:44 ` Niklas Holsti
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox