Subject: hello

From: Moshe Zadka <[email-masked]>
Date: Tue, 7 Nov 2000 22:54:56 +0200 (IST)

The GNU Hello program has two problems:

1. It has too many features, it is complex and difficult to understand.
2. It is encumbered by the GPL, so companies cannot include this in
   their closed-source products, hindering compatibility.

Therefore, I'm releasing the following hello program to the public
domain. Use and enjoy!

Please send complaints or comments to [email-masked]

=======> cut here <==========
/* Released to the Public Domain */
#include <stdio.h>

int main(int argc, char **argv)
{
	printf("hello, world\n");
	return 0;
}
=======> cut here <========

Compilation instructions:

1. Save this file to "hello.c"
2. Run "cc hello.c && mv a.out hello"

If this fails to compile on your favourite platform and you manage
to compile this anyway, please let me know how you did this, so I
can help others and improve portability.

--
Moshe Zadka <[email-masked]> -- 95855124
http://advogato.org/person/moshez

---

From: Omer Mussaev <[email-masked]>
Date: Wed, 08 Nov 2000 11:58:19 +0200

> can help others and improve portability.

Revision:
---------------------------
extern int printf (char*, ... ) ;
main (void)
{
       return printf ("hello world\n")?1:0 ;
}
---------------------------

> To unsubscribe from this group, send an email to:
> [email-masked]

---

From: Moshe Zadka <[email-masked]>
Date: Wed, 8 Nov 2000 11:08:47 +0200 (IST)

> Revision:

Hell, no! I never define prototypes of library functions myself.
What if stdio.h defines it as (const char *, ...)? 
I truly hope that this project will not fork off.

---

From: "Nadav Har'El" <[email-masked]>
Date: Wed, 8 Nov 2000 11:09:43 +0200

>        return printf ("hello world\n")?1:0 ;

Why ?1:0? If printf succeeds, it will return a non-zero value, and you
will return 1, the shell's failure code, which doesn't make sense.
Instead, do 
	return !printf("hello world\n");

But if you want to be more like Moshe's original example, you'd better do:
	return printf("hello world\n"),0;

   or   return printf("hello world\n")*0;

If you want something like the ?1:0 stuff you wrote above, consider the
following alternative that does the same thing:
	return !!printf("hello world\n");
[this method uses two negation instructions, but no jump, so maybe it is
more efficient in pipelining CPUs?]

Aren't C expressions fun? :)

-- 
Nadav Har'El                        |   Wednesday, Nov 8 2000, 10 Heshvan 5761
[email-masked]             |-----------------------------------------
Phone: +972-53-245868, ICQ 13349191 |Unix is simple, but it takes a genius to
http://nadav.harel.org.il           |understand its simplicity.

---

From: Moshe Zadka <[email-masked]>
Date: Wed, 8 Nov 2000 11:23:09 +0200 (IST)

> Aren't C expressions fun? :)

Well, I don't know of a single *real* language (defined as Python/Perl/C)
which this not not trick will not work in.
I'm planning of porting the "hello" application to Python, for easier
maintainence, BTW.

#!/usr/bin/python
print "hello, world"

I'm also considering making it a library so that applications can embed
this more easily.

====> file hello.h <=====
/* Released to the Public Domain */
void hello();
====> file hello.c <=====
/* Released to the Public Domain */
#include <stdio.h>
#include <hello.h>
void hello()
{
	printf("hello, world");
}
====> file test.c <=====
/* Released to the Public Domain */
int main(int argc, char **argv)
{
	hello();
	return 0;
}
======> cut here <======

I hope that pretty soon I'll be able to work on the Python
bindings to libhello.

====> file hellomodule.c <====
#include <Python.h>

static
PyObject *
py_hello(PyObject *self, PyObject *args)
{
	if (!PyArg_ParseTuple(args, ":hello"))
		return NULL;
	hello();
	Py_INCREF(Py_None);
	return Py_None;
}

static PyMethodDef hello_methods[] = {
        {"hello",        (PyCFunction)py_hello,  METH_VARARGS},
        {NULL,          NULL}           /* sentinel */
};

DL_EXPORT(void)
inithello(void)
{
	Py_InitModule("hello", hello_methods);
}
======> cut here <=====

This library is intended to increase portability of hello-world
applications with regards to spelling, capitalization, etc.
Please use it in your application instead of rolling your own!

TODO:
 -- Perl/Tcl/Ruby binding
 -- i18n and l10n
 -- add themes

---

From: "Nadav Har'El" <[email-masked]>
Date: Wed, 8 Nov 2000 11:33:06 +0200

> On Wed, 8 Nov 2000, Nadav Har'El wrote:

... over 60 lines of code removed

> Please use it in your application instead of rolling your own!

Hmmm... Didn't you start this whole thread by saying that GNU hello is
getting too complicated, and you wanted to write a simpler version? ;)

-- 
Nadav Har'El                        |   Wednesday, Nov 8 2000, 10 Heshvan 5761
[email-masked]             |-----------------------------------------
Phone: +972-53-245868, ICQ 13349191 |When you lose, don't lose the lesson.
http://nadav.harel.org.il           |

---

From: Moshe Zadka <[email-masked]>
Date: Wed, 8 Nov 2000 11:49:15 +0200 (IST)

> getting too complicated, and you wanted to write a simpler version? ;)

Yes, but then I realized that a major deficiency of GNU Hello is that it
is a program, rather then a library. Since my version was much simpler
then GNU hello, it was easier to transform it into a library, which
is still simpler then GNU hello. Bindings to other languages don't
complexify the library itself. i18n and l10n are needed, since many
people do not understand English. Themability is important to any
library implementing user-interface nowadays.

Note that to add themeability, I only need to change it in one place,
and I get to keep all my old code as is.

/* Added themablity */
#include <stdio.h>
#include <stdlib.h>

void hello()
{
	char *greeting;

	greeting = getenv("HELLO_GREETING");
	if (!greeting)
		greeting = "hello world";
	printf("%s\n", greeting);
}
=====> cut here <=====

I still need help with the Tcl/Perl/Ruby.

i18n and l10n will have to wait until version 1.0
--
Moshe Zadka <[email-masked]> -- 95855124
http://advogato.org/person/moshez

---

From: Omer Mussaev <[email-masked]>
Date: Wed, 08 Nov 2000 12:52:28 +0200

> I truly hope that this project will not fork off.

in that case it is ok.
By C standard, value of pointer to qualified type can be assigned to pointer
to unqualified type.

---

From: Moshe Zadka <[email-masked]>
Date: Wed, 8 Nov 2000 11:55:02 +0200 (IST)

> By C standard, value of pointer to qualified type can be assigned to pointer

Yes, but C compilers usually emit warnings for such things -- never a good
thing.

---

From: Omer Mussaev <[email-masked]>
Date: Wed, 08 Nov 2000 13:02:56 +0200

>  -- add themes

        mt_safeness
        guile bindings.
        c++ bindings

---

From: Moshe Zadka <[email-masked]>
Date: Wed, 8 Nov 2000 12:10:25 +0200 (IST)

>         c++ bindings

The hello library isn't mt-safe by design: if you want mt-safety, protcect
calls into the library with your own mutex. 

====> hello.hpp <===
/* Released to the Public Domain */
class Hello {
public:
	static void Do_Hello();
private:
	Hello() {} /* don't let anyone create a Hello object */
};
===> file hello.cpp <===
/* Released to the Public Domain */
#include <hello.hpp>
extern "C" {
#include <hello.h>
}
void Hello::Do_Hello()
{
	hello();
}
====> cut here <====
--
Moshe Zadka <[email-masked]> -- 95855124
http://advogato.org/person/moshez

---

From: Shlomi Fish <[email-masked]>
Date: Wed, 8 Nov 2000 14:41:01 +0200 (IST)

> I still need help with the Tcl/Perl/Ruby.

Try SWIG. I think this library is simple enough for that.

Regards,

	Shlomi Fish

----------------------------------------------------------------------
Shlomi Fish        [email-masked] 
Home Page:         http://t2.technion.ac.il/~shlomif/
Home E-mail:       [email-masked]

The prefix "God Said" has the extraordinary logical property of 
converting any statement that follows it into a true one.

---

From: Moshe Zadka <[email-masked]>
Date: Wed, 8 Nov 2000 14:56:27 +0200 (IST)

> Try SWIG. I think this library is simple enough for that.

I'm against SWIG religiously

---

From: Shlomi Fish <[email-masked]>
Date: Wed, 8 Nov 2000 15:22:23 +0200 (IST)

> I'm against SWIG religiously

Can you elaborate why you are against it "religiously"?

Regards,

	Shlomi Fish

---

From: Moshe Zadka <[email-masked]>
Date: Wed, 8 Nov 2000 16:05:44 +0200 (IST)

> Can you elaborate why you are against it "religiously"?

Because in simple cases it's easier to write the code yourself then
preparing the .i files, and in complex cases you have to wrap it in the
target language, and you create dangerous holes in it. Besides, it works
very hard to pretend that Python is Tcl which personally annoys me
(there's a reason I don't program in Tcl, goddammit)

---

From: Omer Zak <[email-masked]>
Date: Wed, 8 Nov 2000 20:34:58 +0200 (IST)

Joining the silly game, which I hope that someone is archiving and will
edit it and turn it into an excellent guide for newbies to the important
and serious subject of "Design Your Software for Portability"...

> I'm planning of porting the "hello" application to Python, for easier

The first line in the above application is not portable!
Some systems install python at /usr/local/bin.  Others may install it in a
subdirectory of /opt.  Yet others may install it in a crazy path due to
the wish to keep binaries in a server exporting them via NFS.
Not to mention those systems, which have/will have both version 1.5.2 and
version 2.0.

> Please use it in your application instead of rolling your own!

Jokes aside, this point is worthy of being taken seriously.  (Ury,
remember that small project?  wink wink)

                                             --- Omer
There is no IGLU cabal.  The Terrible TPP (Tcl+Perl+Python) beast ate them
all!
WARNING TO SPAMMERS:  see at http://www.zak.co.il/spamwarning.html