EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Software Reuse In Embedded code

Started by steve June 15, 2011

Steve at fivetrees wrote:


> Let me give you a concrete example of poor 3rd-party code. I'm currently > using a CPU from AVR (AVR32 family). These come with "code frameworks", > which include "drivers" for on-chip systems and example code to use > them. Now, I have plenty of respect for the silicon. But I'm convinced > that the code framework was put together by a summer intern (or several) > with little experience and some guidance, but no QA. I made the mistake > of using some of these "drivers" - and they've bitten my ass over and over.
Warrant officer is not the officer. Application engineer is not the engineer. VLV
Hi Steve,

On 6/23/2011 3:37 PM, Steve at fivetrees wrote:

>> Code magically gets better just by studing it, it seems. Complexity >> can can only be reduced so much, and algorithms being coded are >> usually complex, so it's has to be studied to be appreciated. People
I don't agree, there. I.e., many libraries are just "lots of mundane code". Nothing earth-shattering or terribly novel. Toughest libraries I've seen are those that try to do FP math *accurately* (i.e., at the fractional ulp level). There, you're better off *buying* than rolling (those sorts of details make my head hurt)
>> tend to recode a rat's nest of code only to produce another rat's >> nest, but it's their familar rat's nest so it seems better. > > Ah, now there I disagree strongly. I write code to be clear and > obviously correct (hint: state machines; table-driven code; no globals; > OOP design ethics in C). I like to be able to understand my own code at > the very least ;).
+42 There's a lot that can be done to give *added* structure to stuff that would otherwise *look* like a rats nest. E.g., most UI's are total crap to code in any way *other* than as an FSM. Not only does this tend to simplify and "robustify" ("You heard it here, first, folks!" :> ) the code, but it makes it a no-brainer to tweak the code at a later date -- just by documenting those data structures (instead of trying to document a ratsnest of spaghetti code)
> (Today's cock-up was because I'm working on a > multi-build family; lots of conditional compilation. Turned out that the > reason a particular state machine wasn't getting maintained was because > I'd told it not to with the current build... d'oh!) > > There's certainly an art to decomposing complexity into a collection of > simple things (I'm not entirely sure it's something one can teach, > even). I guess for me it's a survival instinct thing: I need to be able > to sleep nights, and have confidence that the high-value system we've > just delivered to a certain branch of a national body isn't going to > fall over because of me.
Exactly. You want to be able to look at something "quickly" (bad choice of word) and see where your *obvious* mistake is without sorting through pages of code wondering which *conditional* is "off by one" (">" should have been ">=", etc.). By imposing structure on it, you force mistakes in the "engine" to be more noticeable -- because they affect *lots* of execution paths instead of just one *rare* path.
> Let me give you a concrete example of poor 3rd-party code. I'm currently > using a CPU from AVR (AVR32 family). These come with "code frameworks", > which include "drivers" for on-chip systems and example code to use > them. Now, I have plenty of respect for the silicon. But I'm convinced > that the code framework was put together by a summer intern (or several) > with little experience and some guidance, but no QA. I made the mistake > of using some of these "drivers" - and they've bitten my ass over and over. > > One quick fr'instance: there's some (complex) code to manage the MACB, > which looks after Ethernet traffic. It signals to higher levels that a > message has been received via a Boolean flag. The higher level, running > asynchronously and at a non-controlled rate, would poll this flag, read > the message, and clear the flag. We started seeing cases where it seemed > that the receive mechanism was one message out of step. We realised this > happened when 2 (or more) messages arrived (and were properly buffered) > before the higher level had a chance to poll the Boolean flag. We were > picking up one message, and clearing the flag... and losing the rest.
<frown> I'll give you each "partial blame" on that score. You *could* have looked around to see what the current *state* of the input queue was -- instead of just assuming "there's a message there" (apologies if I am assuming too much, here, based on what little you've said) I've learned that programming defensively when it comes to dealing with the actual iron pays off in spades! E.g., just because there was an interrupt doesn't mean there *should* have been an interrupt! (so, expecting things to *be* indicating an interrupt can bite you) The best advice when it comes to low level drivers is to use the vendor supplied code as examples of what the code *might* want to do. To, hopefully, clarify something that is vague in the datasheet. Like (hardware) app notes, treating them as gospel leads to pain.
In article <vt-dnRwJ-f_4MJ7TnZ2dnUVZ8nKdnZ2d@lyse.net>,
David Brown  <david.brown@removethis.hesbynett.no> wrote:
<SNIP>
> >But I certainly agree that a lot of people have used the GPL without >understanding it - it is very common to equate "open source" and "free >software" with the GPL, and a lot of code is released under the GPL (no >version specified) because "I want other people to be able to use my >code as they wish". In particular, you can find plenty of example code >and libraries for embedded systems under the GPL, even though the author >is quite happy for you to use the code in your own systems with any >other license.
What is missing here is that you can negotiate with an author about a separate contract. I would gladly sign a one thousand dollar contract allowing Microsoft to make millions. (Non-exclusive, non-transferable, but no obligation to publish source based on my GPL-ed code.) The BSD author would got nada. Groetjes Albert
>
-- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
On 24/06/2011 14:21, Albert van der Horst wrote:
> In article<vt-dnRwJ-f_4MJ7TnZ2dnUVZ8nKdnZ2d@lyse.net>, > David Brown<david.brown@removethis.hesbynett.no> wrote: > <SNIP> >> >> But I certainly agree that a lot of people have used the GPL without >> understanding it - it is very common to equate "open source" and "free >> software" with the GPL, and a lot of code is released under the GPL (no >> version specified) because "I want other people to be able to use my >> code as they wish". In particular, you can find plenty of example code >> and libraries for embedded systems under the GPL, even though the author >> is quite happy for you to use the code in your own systems with any >> other license. > > What is missing here is that you can negotiate with an author > about a separate contract. I would gladly sign a one thousand > dollar contract allowing Microsoft to make millions. > (Non-exclusive, non-transferable, but no obligation to publish > source based on my GPL-ed code.) > The BSD author would got nada. >
That's absolutely true (case in point - when MS took the TCP/IP stack from FreeBSD for use in Windows, they could do so freely and legally and gave nothing back but a small copyright notice in a file that no one noticed). Another example is FreeRTOS - it is licensed under a modified GPL that anyone can use under certain restrictions (such as giving your customers the source code to any changes you made). Or you can buy a license for the same code with different terms. The FreeRTOS developers and users get the best of both worlds. But if FreeRTOS had been under a BSD license, the authors would have got very little out of it.

David Brown wrote:

> On 23/06/11 18:32, Walter Banks wrote: > > > I would have agreed with you 20 years ago. Most of the frivolous > > patents were being filed about then. A surprisingly large amount of the > > current software actually is 20 or more years old. If for example GNU > > had been patented it would be in the public domain by now as it is > > it is protected by copyright and is years away from being in the > > public domain. > > > > New ideas in software development are getting rare which is why > > real breakthroughs should be commercially protected. > > > > You've got that totally backwards. > > It is correct that new ideas in software development are getting rare - > most of the ideas that were truly novel and inspired, and could arguably > justify getting patents, were developed 20 years ago (actually, most of > the important stuff was 30, 40 or more years ago). > > However, the rate of filings for software patents keeps growing. The > obvious conclusion is that a higher and higher percentage, and absolute > number, are totally frivolous.
I am arguing for a software IP commercial protection scheme of some sort to deal with real software breakthroughs. Originally manufacturers paid royalties to the patent holder as part of the business plan to among other things protect their manufacturing business investment. There is no similar parallel in software. It might also be interesting to find out how many cases of software patent abuses readers of this news group have first hand experience. I have been around intellectual property for most of my adult life and have had personal experience with a single example 20+ years ago. Regards, w.. -- Walter Banks Byte Craft Limited http://www.bytecraft.com
On Jun 23, 6:37=A0pm, Steve at fivetrees <st...@NOSPAMTAfivetrees.com>
wrote:
> On 23/06/2011 03:35, steve wrote: > > >> Looking "under the hood" of so-called commercial libraries, I'm > >> > =A0terrified - the standard of coding from so-called expert houses i=
s
> >> > =A0appalling. > > Appalling or just difference of style, organization, and/or > > unfamilarity? > > All of the above, sure. But (putting style etc aside) ultimately lack of > robustness, and just plain old bugliness. > > > You never been bitten with problems in your code? > > Sure. But these days they tend to be typos, rather than car crashes. > > > Code magically gets better just by studing it, it seems. Complexity > > can can only be reduced so much, and algorithms being coded are > > usually complex, so it's has to be studied to be appreciated. People > > tend to recode a rat's nest of code only to produce another rat's > > nest, but it's their familar rat's nest so it seems better. > > Ah, now there I disagree strongly. I write code to be clear and > obviously correct (hint: state machines; table-driven code; no globals; > OOP design ethics in C). I like to be able to understand my own code at > the very least ;).
Ok, let me ask the opposite question, since I can't evaluate yours or anyone elses claims, how many resell their software, where the customer reuses it as-is in a wide variety of unrelated products. That surely is an more objective measure of code reuseability. You said that the head honcho of well-known embedded RTOS supplier had terrible coding guidelines, but they must be selling lots of code to someone repeatedly to be well known so how do you resolve that apparent conflict? Maybe marketing. But the only reasonable answer is his coding guidelines are different, not better or worse then yours. I don't know if he was against table driven code or pro globals but certainly their are situations where higher levels of code abstraction aren't necessarily the best solution and trying to shoe horn those concepts into a product may result is an inferior product that has limited uses (due to performance, say).
Hi David,

On 6/23/2011 2:35 PM, David Brown wrote:
>> If you want to encourage innovation, then don't put silly >> obstacles in the way that others have to waste time >> working around. (e.g., writing your own standard libraries >> just to get around GPLL). > > I agree with this - the GPL is (normally) a poor choice of licence for a > library. But it's a perfectly good choice for an end-user product > (assuming you want to give out the source code, of course).
I don't see a difference between library and product. "If you want to encourage innovation..." If *others* didn't encumber their code with this sort of cruft, *your* job would be easier. You would produce better products, for less investment cost and in less time. Likewise, others would benefit from you unencumbering your code! Unfortunately, *you* (speaking metaphorically) don't want to do this with *your* IP -- until others have done it with *theirs*. So, everyone hides their hole cards and everyone pays more to develop products and takes longer to do so and there is less innovation and ...
>> If I mention open source to a client as a possible short-circuit >> for some portion of the project, the first thing out of their >> mouth is "We don't want to use Linux". *Period* (i.e., drop >> this line of discussion or we'll find someone else who'll >> meet our goals). They equate OSS with Linux and, thus, the GPL >> and rule everything out in one fell swoop. > > That's clearly a client who doesn't know what open source means, and I > would be very careful about a client with such vigorous opinions about > licensing that they don't understand. Make sure you have very clear and > tight contracts before working with such people - they are likely to > believe they have more rights to the work you do for them than they > should have.
People are afraid of open source. They don't see what's in it for them. They just see what it might *cost* them. It's a change. People don't like change. People also tend to have unrealistic expectations! I had a client insist that everything I did for him *only* benefit him. I told him that made perfect sense to me. But, that I would have to *do* everything for him "from scratch", clean-room style -- since I couldn't ethically put work done for previous clients at risk if he opted to go after them for work that "strongly resembled" stuff I was going to do for him (because *he* inherited from them!). In practical terms, this meant he would have to pay a lot more for his product development. Just for the (selfish?) want of being able to say, "Mine! Mine! ALL Mine!!". Amazing how quickly people rethink their positions when there is a price tag associated with it! ;-)
>> The products that *do* include GPL'd software all seem to violate >> at least the *spirit* of the license. Few companies make it easy >> to get a hold of the sources that they are supposed to make available >> under the license. Some go belly-up -- or are bought out (and >> "magically" released from their license obligations?). Others >> comply only with the *letter* of the license. "Here's a CD >> with the source code on it. *You* figure out how to unpack it, >> set up the build environment, etc. We don't *support* it..." > > There is definitely a fair amount of that going on - there is the full > spectrum of attitudes from keeping everything as secret as they can > (legally or illegally) to being fully open and encouraging tinkering. > The majority of embedded systems using GPL'ed software probably fall > into the "we'll give you a CD of the source code if you ask us" category.
I've gone looking for sources for GPL'd products many times. If the company has gone belly-up or bought out, good luck! So, they benefitted (even if only for the duration of their short-lived existence) from the terms of the license -- yet no one else gets to build on their efforts. [linksys is pretty good about making sources available. IIRC, there's a page that lists the sources for each such product they've offered. I wonder if the sources will "disappear" 3 years after the products? Or, will the company figure the cost of the page is nothing in the long run]
> But is that the fault of the GPL, or of people who publish code under > the GPL? Should the busybox author have released his code under the BSD > to allow companies to modify it and use it, then keep the improvements
Depends on the desires of the author. It's *my* belief that unencumbering code encourages reuse far more than the GPL ever will. The more code gets reused, the higher the bar gets raised. I.e., GPL'd code now has to compete with *truly* "free" code -- "Why should I use your GPL'd code and have to conform to its more restrictive license when this *other* code does all the same -- and more -- and is *free*?"
> secret from their users? Or is it the fault of the abusing companies who > took this substantial code for free, and ignored the license? How would
I'm not addressing license violations. With existing law, there's nothing you can do about that. OTOH, if everyone could just as easily compete with that violator, it puts pressure on the violator to truly innovate to stay ahead of everyone else that could "freely" use that code.
> you feel if you had written the code and charged for licenses, and > someone had then based their products around your code without paying > you your dues? It is exactly the same thing.
That's a problem with the current law and practices. Folks know what risks they face when publishing, producing and/or licensing software. If you don't want to face those risks, then don't play in that profession! I have little sympathy for a *policeman* complaining that people are *shooting* at him! ;-)
> Programmers are under no obligation to write code to a license that > /you/ find easier to use for free in your money-making products! > > It is certainly /nice/ when programmers use a license that lets you use > their code without giving away your own code. I like the MPL-style > licence, or the "GPL with exceptions" licenses such as used by FreeRTOS. > I think that is a good compromise license in many cases, especially for > software in embedded systems. > > But whether you like it or not, a lot of software has a GPL licence. The > terms are not that bad - they are much less restrictive than in many > commercial licences (even when you exclude all mention of costs). If you > don't like it, get your software from some other source - just as you > would with any other software under any other licence. It's no different.
Exactly. And, since there *are* other options, my point of the value of something like the GPL *diminishing* as more alternatives are available becomes more significant. There's very little that's GPL'd that doesn't also have a "free" alternative available. Why would I -- as a businessman -- want to needlessly encumber my work when I don't have to?
Hi Walter,

On 6/24/2011 5:40 AM, Walter Banks wrote:

> It might also be interesting to find out how many cases of software > patent abuses readers of this news group have first hand experience. > I have been around intellectual property for most of my adult life and > have had personal experience with a single example 20+ years ago.
Amusingly, the only first-hand experience I have of IP theft is direct copyright infringement. I.e., manufacturer B *literally* copying the code in manufacturer A's product, making *superficial* changes and then passing it off as his own. This was commonplace in the gaming field in the 80's. It was *so* common that the (software) mechanisms built into the games to detect and/or thwart this practice were informally referred to as "Jap-zappers" (because most of the counterfeit machines were coming from Japan). At least some of the "Easter Eggs" in games of this vintage were trade secret, designed to be resistant to tampering and intended to unambiguously identify the original author in future litigation ("Mr. Defendant, could you please explain to the court why *your* game displays the *Plaintiff's* name on the screen when I push this magical series of buttons?")
On Thu, 23 Jun 2011 23:17:25 +0200, David Brown
<david.brown@removethis.hesbynett.no> wrote:

>On 23/06/11 21:01, George Neuner wrote: >> >> GPL v1& v2 were not too objectionable, but there has been a general >> backlash against GPL v3. It's largest failure to date has been Linus >> Torvald's categorical refusal to put Linux under v3. > >As far as Linux goes, Linus Torvalds is very much a pragmatist. When >publishing Linux, he felt the GPL v2 expressed what he wanted in a >license, so he used it. Since the GPL v2 did the job, he explicitly >limited Linux to the GPL v2 (standard GPL's allow the the code to be >re-licensed under newer versions). Having made that decision early on, >it was fixed. Linus is not in the position to change it now - that >would require the permission of every contributor to Linux over the >years (or the removal of their code). So when the question of putting >Linux under the GPL v3 came up, he made it barely bothered discussing >something that was clearly impossible (and that he didn't agree with >anyway).
Not exactly. You're absolutely correct that many contributors would need to OK putting a distribution under new license, and the effort to do that is considerable ... but Torvalds himself maintains exclusive control over licensing of the kernel. He has written extensively about his dislike for GPL v3 and why he felt the kernel could not be subjected to it - much of which has to do with the increasing use of Linux in embedded systems. George
Don Y wrote:

>If I mention open source to a client as a possible short-circuit >for some portion of the project, the first thing out of their >mouth is "We don't want to use Linux". *Period* (i.e., drop >this line of discussion or we'll find someone else who'll >meet our goals). They equate OSS with Linux and, thus, the GPL >and rule everything out in one fell swoop.
At a previous employer, a large project was ported from Linux to NetBSD because of similar concerns. Or may be, I should say "it was ported from a GPL license to an MIT license." -- Roberto Waltman [ Please reply to the group. Return address is invalid ]

The 2024 Embedded Online Conference