From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,640b65cbfbab7216 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Untyped Ada? Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <47F26C46.3010607@obry.net> <44d88b93-6a90-4c18-8785-2164934ba700@a9g2000prl.googlegroups.com> <28302e25-844c-41e1-87f1-b4a86146f330@s19g2000prg.googlegroups.com> Date: Sat, 5 Apr 2008 10:44:00 +0200 Message-ID: <136osxt9jv5ho.xvy2zm6b5kkp.dlg@40tude.net> NNTP-Posting-Date: 05 Apr 2008 10:44:00 CEST NNTP-Posting-Host: 8b741a97.newsspool3.arcor-online.net X-Trace: DXC=GKRXiLg4D]ncZ]`hZ;1McF=Q^Z^V384Fo<]lROoR1^;5]aA^R6>2Q55Nc1KmF:<[6LHn;2LCV>[ On Fri, 4 Apr 2008 12:14:38 -0700 (PDT), Graham wrote: > On Apr 4, 6:38 pm, "Dmitry A. Kazakov" > wrote: >> On Fri, 4 Apr 2008 08:16:04 -0700 (PDT), Graham wrote: >>> I haven't been using Ada for all that long, but I have been thinking >>> that a kinder, gentler version would be nice in some circumstances. >>> Not necessarily *no* type-checking, but the ability to mix, say, >>> integers, fixed-point types and floats in an equation without >>> cluttering up the code with conversions. >> >> But you can do that. Provided you knew the semantics of Integer + Float >> your hands are free. Define >> >> function "+" (Left : Integer; Right : Float) return Float; >> >> Here you are. >> > The 'Ada way' is to define lots of types, right? So you could end up > having to maintain hundreds of these functions, couldn't you? Do > people do that? Just curious. Yes they do, because it is not hundreds in Ada. It has inheritance and generics in order to support reuse. >> The compiler does not define it for you for just one reason. The semantics >> of this operation cannot be universally defined. Integers and Floats have >> contradicting algebraic properties. + is exact for the former and inexact >> for the latter. Therefore if adding them makes sense, that is specific for >> the application which gives an interpretation to Integer and Float in some >> way. In other words it is your business. > > That's the kind of almost philosophical argument I find baffling. > People write programs every day that mix integers and floats in > calculations, without any special handling, and the results usually > make sense. ...and the programs usually work, you mean. Granted. Now let us return to your argument about maintaining hundreds of functions. Considering that "usual" means 99% of cases, that gives us 1% x 100 = 100% fault rate. Thus it does *not* work "usually". Further when it does not, how would you find and fix the problem? The idea of Ada is that catching inconsistencies earlier is less expensive, though admittedly more uncomfortable for programmers) than sending bags to Milan later. >>> I dare say that you wouldn't want to program a missile in such a loose >>> way, but for the kinds of things I'm involved in - financial apps and >>> simulations - the level of strictness of Ada would be a turn-off for >>> many developers. >> >> This puzzles me. Do not financial applications have quite strict >> requirements imposed numeric behavior? Or are you writing for Bear Stearns? >> (:-)) >> > > Above all, they have requirements for clarity. Suppose I have > something like: > > tax : Money; -- some kind of fixed-point or decimal > tax_rate : Rate; -- some kind of float > quantity : Integer; -- or some such > > I want to be able to write: > > tax = tax_rate * price * quantity; > > Because that way everyone can concentrate on the logic of what's going > on, rather the mechanics of it. > > If instead I have to write: > > tax = Money(tax_rate * Rate( price ) * Rate( quantity )); > > then that's much harder to follow. Thank you for making my argument! The above immediately indicates a problem. Granted, I am not a financial expert, but I guess it is semantically wrong. What do you multiply first: 1. (tax_rate * price) * quantity 2. tax_rate * (price * quantity) I bet only second is correct. So I would insist to define: function "*" (Left : Money; Right : Natural) return Money; function "*" (Left : Natural; Right : Money) return Money; function "*" (Left : Tax_Rate; Right : Money) return Money; function "*" (Left : Money; Right : Tax_Rate) return Money; (I wished some syntax to instruct the compiler to derive commutative operations and complements, as it does for "/=". But this is another story) >>> Sorting out string handling out would be nice, too. >> >> What do you mean? In fact Ada's fixed strings handling is the best I know. >> You should never need Unbounded_String except for rare cases, when you >> wanted to return two strings out of one function. > > I don't understand that at all. For any web based application (at > least) you need unicode and you can't rely on strings being any > particular length. Yet I use exclusively fixed length strings! The trick is that you never need truly varying strings. If you feel you need it, then try to reconsider the design, because in most cases varying strings is a wrong design. The reason is that a string is either the user/GUI/protocol input, which determines its length, or, when you compose strings, then that is either primitive catenation or else filling a buffer of a fixed length. If you need UTF-8 string handling in Ada, you might have a look at my take of how it should be: http://www.dmitry-kazakov.de/ada/strings_edit.htm -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de