Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > "Functional"

Reply
Thread Tools

"Functional"

 
 
BartC
Guest
Posts: n/a
 
      09-30-2013


"Ian Collins" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Malcolm McLean wrote:
>> On Monday, September 30, 2013 9:54:40 AM UTC+1, Ian Collins wrote:
>>> Malcolm McLean wrote:
>>>
>>>
>>> LibXML is pretty universal. Any platform with PHP or (I think) Python
>>> installed will already have it.
>>>

>> You can't give a program that depends on LibXML to a Windows user
>> and expect them to compile it. The Windows machine I'm typing this
>> on doesn't have it. In half an hour I'll turn on a Linux machine
>> then it's as simple as typing "app-get". But the world doesn't use
>> Linux or corporate development Windows machines with all the bits
>> and bats installed.

>
> So you expect windows users to be using your X toolkit?
>
> Seriously, if every piece of software that uses XML included its own
> parser, half the programming world would be writing XML parsers. That's
> why we have libraries.


Yes, but massive great libraries which half the time are dwarfing the tasks
they called upon to deal with.

In Malcolm's case, he is parsing XML which he himself has generated. So the
program can be minimal (but retaining the advantage of being in a standard
format).

I recently was thinking about using XML (to store a program structure), but
have had unhappy dealings with XML before. I instead creating my own format
(the file doesn't need to go anywhere) to do the same thing. The parser is
about 150 lines of code.

--
Bartc

 
Reply With Quote
 
 
 
 
Les Cargill
Guest
Posts: n/a
 
      09-30-2013
Malcolm McLean wrote:
> On Sunday, September 29, 2013 9:45:47 PM UTC+1, Keith Thompson wrote:
>> Malcolm McLean <(E-Mail Removed)> writes:
>>
>> If your data is not inherently recursive, perhaps XML is not the best
>> way to represent it.
>>

> XML is a sort of accepted standard for information exchange. I
> use if for the Baby X resource compiler, not because the data is
> complex or recursive - essentially it's just a list of files to
> pack into a compileable C source - but because it's easier than
> defining a custom convention.
> Whilst you can represent trees or other recursive structures in
> XML directly, most XML files aren't like that.
>>
>> In any case, it seems wasteful to write a custom parser that handles a
>> *subset* of XML when there are so many open source full XML parsers out
>> there. A custom parser might be smaller in terms of total code size,
>> but a full parser is much smaller in terms of code *that you have to
>> write and maintain*.
>>

> I wrote a vanilla xml parser (http://www.malcolmmclean.site11.com/www).
> There were other parsers available on the web, but I didn't like
> any of them. The snag is that to support the full xml spec you need
> lots of complex code, and then to load in a massive file you have to
> devise a complex system for keeping most of it on disk. The XML people
> call it a "pull parser". This is all overkill if you just want a crossword
> file containing a 15x15 grid and maybe thirty one-line clues, or a
> list of maybe a dozen files.



I was directed to ezXML at one point, and it's a nice, simple XML
parser. It only gets you to "leaf nodes" and then you have to interpret
it into a coherent whole by traversing child/sibling pointer
relationships.

Just in case you are interested in/tired of maintaining your own.

http://ezxml.sourceforge.net/

> If you use a library then no-one can compile your code unless they
> have that library installed, which means that no-one will compile
> your code unless very motivated to use it. If you ship pages and
> pages of source then the program becomes hard to understand. You also
> potentially have legal problems, for instance Microsoft won't permit
> their free compilers to be used on anything with a "viral" licence.
>
> On the other hand it is better to do things properly.
>

--
Les Cargill

 
Reply With Quote
 
 
 
 
Malcolm McLean
Guest
Posts: n/a
 
      09-30-2013
On Monday, September 30, 2013 1:26:46 PM UTC+1, Les Cargill wrote:
>
>
> I was directed to ezXML at one point, and it's a nice, simple XML
> parser. It only gets you to "leaf nodes" and then you have to interpret
> it into a coherent whole by traversing child/sibling pointer
> relationships.
>
> Just in case you are interested in/tired of maintaining your own.
>
>
>
> http://ezxml.sourceforge.net/
>
>


I've just looked at the source.

#include <unistd.h>
#include <sys/types.h>

So unfortunately it won't compile on every C compiler.
It's probably perfectly good if you can guarantee a Unix-like system,#but it can't replace the vanilla xml parser.


 
Reply With Quote
 
Stephen Sprunk
Guest
Posts: n/a
 
      09-30-2013
On 30-Sep-13 03:24, Malcolm McLean wrote:
> On Sunday, September 29, 2013 9:45:47 PM UTC+1, Keith Thompson
> wrote:
>> In any case, it seems wasteful to write a custom parser that
>> handles a *subset* of XML when there are so many open source full
>> XML parsers out there. A custom parser might be smaller in terms
>> of total code size, but a full parser is much smaller in terms of
>> code *that you have to write and maintain*.

>
> I wrote a vanilla xml parser
> (http://www.malcolmmclean.site11.com/www). There were other parsers
> available on the web, but I didn't like any of them. The snag is that
> to support the full xml spec you need lots of complex code, and then
> to load in a massive file you have to devise a complex system for
> keeping most of it on disk.


That depends on what you mean by "massive"; there shouldn't be any
problem loading typical files of reasonable size on 32-bit systems or
even ridiculously large files on 64-bit systems. Let the OS's virtual
memory system deal with mapping data in and out as needed.

> This is all overkill if you just want a crossword file containing a
> 15x15 grid and maybe thirty one-line clues, or a list of maybe a
> dozen files.


So you load it, extract the data you need, and then unload it.

> If you use a library then no-one can compile your code
> unless they have that library installed, which means that no-one will
> compile your code unless very motivated to use it.


A dependency on a common XML library shouldn't be a big deal; most
programs I deal with depend on a dozen or more libraries, of which I
usually have most or all of them install already anyway. If you're
really worried about it, just include the library's code within your
distribution (either source or binary). That's still better than having
to write and maintain your own XML parser.

S

--
Stephen Sprunk "God does not play dice." --Albert Einstein
CCIE #3723 "God is an inveterate gambler, and He throws the
K5SSS dice at every possible opportunity." --Stephen Hawking
 
Reply With Quote
 
Malcolm McLean
Guest
Posts: n/a
 
      09-30-2013
On Monday, September 30, 2013 7:38:41 PM UTC+1, Stephen Sprunk wrote:
>
> A dependency on a common XML library shouldn't be a big deal; most
> programs I deal with depend on a dozen or more libraries, of which I
> usually have most or all of them install already anyway. If you're
> really worried about it, just include the library's code within your
> distribution (either source or binary). That's still better than having
> to write and maintain your own XML parser.
>

Once you depend on half a dozen libraries, adding an extra dependency isn't
a big change. But going from idempotency to having an external dependency
is a big step in the wrong direction. It means that your code is unlikely
to remain useful for very long, because sooner or later one of the externals
is going to break, become unavailable, require a proprietary compiler, or
otherwise cause the program to fail. An ffmpeg build broke on Microsoft, for
example. I suspect it was done deliberately.

Have you actually read the vanilla xml parser? It took about a day to write.
In my view, that's time well invested. It won't handle arbitrarily complex
xml that depends on all the difficult areas of the standard. But any time I
need a config file or a small database, I can simply include this one file.
If something goes wrong, the source is simple enough for any competent C
programmer to understand it in an hour so so.

Once code passes a certain level of complexity, you need to maintain it.
It uses various constructs or depends on externals which break. But simple,
standard C functions, generally you don't.
 
Reply With Quote
 
Stephen Sprunk
Guest
Posts: n/a
 
      10-01-2013
On 30-Sep-13 15:00, Malcolm McLean wrote:
> On Monday, September 30, 2013 7:38:41 PM UTC+1, Stephen Sprunk
> wrote:
>> A dependency on a common XML library shouldn't be a big deal; most
>> programs I deal with depend on a dozen or more libraries, of which
>> I usually have most or all of them install already anyway. If
>> you're really worried about it, just include the library's code
>> within your distribution (either source or binary). That's still
>> better than having to write and maintain your own XML parser.

>
> Once you depend on half a dozen libraries, adding an extra dependency
> isn't a big change.


Exactly.

> But going from idempotency to having an external dependency is a big
> step in the wrong direction. It means that your code is unlikely to
> remain useful for very long, because sooner or later one of the
> externals is going to break, become unavailable, require a
> proprietary compiler, or otherwise cause the program to fail.


As I said, if you're worried about that, just include the library's code
within your distribution so there's no external build-time or run-time
dependency. Many projects do that, especially on Windows.

> Have you actually read the vanilla xml parser? It took about a day to
> write. In my view, that's time well invested. It won't handle
> arbitrarily complex xml that depends on all the difficult areas of
> the standard. But any time I need a config file or a small database,
> I can simply include this one file. If something goes wrong, the
> source is simple enough for any competent C programmer to understand
> it in an hour so so.


I don't doubt that; I'm just not a fan of reinventing the wheel.

S

--
Stephen Sprunk "God does not play dice." --Albert Einstein
CCIE #3723 "God is an inveterate gambler, and He throws the
K5SSS dice at every possible opportunity." --Stephen Hawking
 
Reply With Quote
 
Seebs
Guest
Posts: n/a
 
      10-01-2013
On 2013-09-30, Malcolm McLean <(E-Mail Removed)> wrote:
> Once you depend on half a dozen libraries, adding an extra dependency isn't
> a big change. But going from idempotency to having an external dependency
> is a big step in the wrong direction. It means that your code is unlikely
> to remain useful for very long, because sooner or later one of the externals
> is going to break, become unavailable, require a proprietary compiler, or
> otherwise cause the program to fail.


How long is "very long"? I've had code that depends on curses run pretty much
consistently from the late 80s through today.

-s
--
Copyright 2013, all wrongs reversed. Peter Seebach / http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
Autism Speaks does not speak for me. http://autisticadvocacy.org/
I am not speaking for my employer, although they do rent some of my opinions.
 
Reply With Quote
 
Malcolm McLean
Guest
Posts: n/a
 
      10-01-2013
On Tuesday, October 1, 2013 9:54:31 AM UTC+1, Seebs wrote:
> On 2013-09-30, Malcolm McLean <(E-Mail Removed)> wrote:
>
> > Once you depend on half a dozen libraries, adding an extra dependency isn't
> > a big change. But going from idempotency to having an external dependency
> > is a big step in the wrong direction. It means that your code is unlikely
> > to remain useful for very long, because sooner or later one of the externals
> > is going to break, become unavailable, require a proprietary compiler, or
> > otherwise cause the program to fail.

>
> How long is "very long"? I've had code that depends on curses run pretty much
> consistently from the late 80s through today.
>

In my case, we had a machine, a single 386 that served 20 of us, that ran
curses. But I bought a DOS machine for myself, and I had a whole 386
processor just for me. Fortunately the instructor had told us to write
a little abstraction layer over curses, so I rewrote it for DOS, and I could
shuttle code between my home machine and the class.
Then I got a Unix machine for my first job, so curses would have been
useful again. Except that it also ran X. Most of the user were artists,
they didn't like curses-type interfaces. Next job was Windows and games
console based.
Then I used a Linux machine for my PhD. So I could have dusted off my
old curses code. But it was long forgotten by then. However I've got a file to
load in a bitmap I wrote when I had the first 386. If you look at the Baby X
resource compiler (http://www.maclolmmclean/site11.com/...byX/BabyX.html )
you can see it. It's still going strong.
 
Reply With Quote
 
Aleksandar Kuktin
Guest
Posts: n/a
 
      10-01-2013
Hello group!

On Tue, 01 Oct 2013 02:17:15 -0700, Malcolm McLean wrote:

> [snip]
>
> If you look at the Baby X resource compiler
> (http://www.maclolmmclean/site11.com/...byX/BabyX.html ) you can see
> it. It's still going strong.


This URL is definitely not transporting me to BabyX. I tried
`http://www.malcolmmclean.site11.com/www' that you mentioned in one of
the previous posts, but that was also a dud. It was only when I went to
`http://www.malcolmmclean.site11.com/' and clicked on the 'www/' that I
was able to get somewhere.

I'm using Midori.
 
Reply With Quote
 
Nobody
Guest
Posts: n/a
 
      10-02-2013
On Mon, 30 Sep 2013 23:41:39 +1300, Ian Collins wrote:

> Seriously, if every piece of software that uses XML included its own
> parser, half the programming world would be writing XML parsers.


And most of them would be half-baked parsers for whichever unspecified
subset of XML the program uses for its output (i.e. not actually XML at
all, just something similar enough to confuse people).

If you're going to support XML, you need to accept any file which matches
the schema, not just those which the application generated itself.
Otherwise, you can't edit the files with standard tools, can't create
files with standard libraries, etc. IOW, you may as well just fwrite() the
in-memory representation to disc.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
a = [ "1", "2", "3" ] v/s a = new Array ( "1", "2", "3" )identical in all ways? okey Javascript 1 08-25-2009 12:56 PM
What is the "functional" way of doing this? beginner Python 17 08-01-2007 04:16 PM
HTML Functional Equivalent Of "Include" or "CopyLib"? (Pete Cresswell) HTML 2 11-06-2004 03:39 PM
<FORM METHOD="post" onSubmit="return fieldcheck()" name="orientation" action="http://ws-kitty.BU.edu/AT/survey/orientation/script/write.asp" language="JavaScript"> Joeyej ASP .Net 0 06-04-2004 07:55 PM
["a", "b", "c", "d"] to "a, b, c, d"? Martin Ruby 3 04-07-2004 02:11 PM



Advertisments