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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,24d7acf9b853aac8 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!y11g2000yqm.googlegroups.com!not-for-mail From: Natacha Kerensikova Newsgroups: comp.lang.ada Subject: Re: S-expression I/O in Ada Date: Sat, 7 Aug 2010 05:56:50 -0700 (PDT) Organization: http://groups.google.com Message-ID: <13b07f2c-2f35-43e0-83c5-1b572c65d323@y11g2000yqm.googlegroups.com> References: <547afa6b-731e-475f-a7f2-eaefefb25861@k8g2000prh.googlegroups.com> <1qk2k63kzh7yv$.3jgc403xcqdw$.dlg@40tude.net> <8ae8e899-9eef-4c8c-982e-bfdfc10072f1@h17g2000pri.googlegroups.com> <258zlxrv4fn6.1vszho1rtmf48$.dlg@40tude.net> <984db477-973c-4a66-9bf6-e5348c9b95f2@n19g2000prf.googlegroups.com> <46866b8yq8nn$.151lqiwa0y2k6.dlg@40tude.net> NNTP-Posting-Host: 95.152.65.220 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1281185810 32242 127.0.0.1 (7 Aug 2010 12:56:50 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 7 Aug 2010 12:56:50 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: y11g2000yqm.googlegroups.com; posting-host=95.152.65.220; posting-account=aMKgaAoAAAAoW4eaAiNFNP4PjiOifrN6 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.9.2.3) Gecko/20100524 Firefox/3.6.3,gzip(gfe) Xref: g2news1.google.com comp.lang.ada:12930 Date: 2010-08-07T05:56:50-07:00 List-Id: On Aug 7, 10:39=A0am, "Dmitry A. Kazakov" wrote: > One cannot judge a format without knowing what is the purpose of. Most of > the formats like S-expressions are purposeless, in the sense that there i= s > no *rational* purpose behind them. As you wrote above, it is either legac= y > (we have to overcome some limitations of some other poorly designed > components of the system) or personal preferences (some people like angle > brackets others do curly ones). Why can't there be general-purpose format, just like there are general- purpose programming languages? Can we at least agree on the fact that a sequence of bytes is a general-purpose format, widely used for storing and transmitting data? (this question is just a matter of vocabulary) Now byte sequences are a very crude format, because it doesn't have any semantics besides what the application specifically put into it. So let's add as few semantics as possible, to keep as much generality as possible. We end up with a bunch of byte sequences, whose semantics are still left to the application, linked together by some kind of semantic link. When the chosen links are "brother of" and "sublist of" you get exactly S-expressions. The almost-RFC I linked is only this definition along with a standardization of how to serialize the links and the bytes sequences. This is undoubtedly still a crude format. You might argue it's useless to add so little semantics on top of byte sequences, and that serialization should be engineered only when you what you are about to serialize, i.e. make a much larger leap between byte sequences and meaningful objects. I might even agree on a philosophical point of view. However from a purely practical point of view, and using the fact that in my background languages (C and 386 asm) bytes sequences and strings are so similar, these crude semantics are all I need (or at least, all I've ever needed so far). Now if we agree that simplicity is a desirable quality (because it leads to less bugs, more productivity, etc), I still fail to see the issues of such a format. When I mentioned earlier flexibility as a strong point for S- expressions, I meant that just like byte sequences, they can accommodate whatever purpose you might want to put on top of them. Now regarding personal preferences about braces, I have to admit I'm always shocked at the way so many people dismiss S-expressions on first sight because of the LISP-looking parentheses. I'm very glad I can have a higher-level conversation about them. > > The other application is actual serialization, > > That should not be a text. I tend to agree with that as a generality, however I believe some particular cases might benefit from a text-based serializations, in order to harness the power of existing text-based tools. > >>> But now that I think about it, I'm wondering whether I'm stuck in my = C > >>> way of thinking and trying to apply it to Ada. Am I missing an Ada wa= y > >>> of storing structured data in a text-based way? > > >> I think yes. Though it is not Ada-specific, rather commonly used OOP d= esign > >> patterns. > > > I heard people claiming that the first language shapes the mind of > > coders (and they continue saying a whole generation of programmers has > > been mind-crippled by BASIC). My first language happened to be 386 > > assembly, that might explain things. > > I see where mixing abstraction layers comes from... Could you please point me where I am mixing what? I genuinely want to learn, but I just don't understand what you're referring to. > > Anyway, I genuinely tried OOP > > with C++ (which I dropped because it's way too complex for me (and I'm > > tempted to say way too complex for the average coder, it should be > > reserved to the few geniuses actually able to fully master it)), but I > > never felt the need of anything beyond what can be done with a C > > struct containing function pointers. > > Everything is Turing-complete you know... (:-)) I should know, I was accessing from assembly some (DirectX) C++ objects' vtable array before I knew anything about OOP. My point is, most of my (currently non-OOP) code can be expressed as well in an OOP style. When I defined a C structure along with a bunch of functions that perform operations on it, I'm conceptually defining a class and its methods, only expressed in a non-OOP language. I sometimes put function pointers in the structure, to have a form of dynamic dispatch or virtual methods. I occasionally even leave the structure declared but undefined publicly, to hide internals (do call that encapsulation?), along with functions that could well be called accessors and mutators. In my opinion that doesn't count as OOP because it doesn't use OOP-specific features like inheritance. > > The > > problem is, I just can't manage to imagine how to go in a single step > > from the byte sequence containing a S-expression describing multiple > > objects to the internal memory representation and vice-versa. > > You need not, that is the power of OOP you dislike so much. I don't dislike at all. I just seldom think that way. I've met people who saw objects everywhere, while I tend to see bunch of bits everywhere. As a part of demoscene said when I learned programming, "100% asm, a way of life". > Consider each > object knows how to construct itself from a stream of octets. It is trivi= al > to simple objects like number. E.g. you read until the octets are '0'..'9= ' > and generate the result interpreting it as a decimal representation. Or y= ou > take four octets and treat them as big-endian binary representation etc. > For a container type, you call the constructors for each container member > in order. If the container is unbounded, e.g. has variable length, you re= ad > its bounds first or you use some terminator in the stream to mark the > container end. For containers of dynamically typed elements you must lear= n > the component type before you construct it. That's exactly how I use S-expressions, except that instead of starting from a stream of octets, I start from an array of octets (whose length is known), but if I understood correctly that doesn't change your point. And the reason why I started this thread is only to know how to buffer into memory the arrays of octets, because I need (in my usual use of S-expressions) to resolve the links between atoms before I can know the type of atoms. So I need a way to delay the typing, and in the meantime handle data as a generic byte sequence whose only known information is its size and its place in the S- expression tree. What exactly is so bad with that approach? I hope I don't bother you too much with my noobity and my will to understand, Natacha