* another day of cutting edge Elisp (read from a file to a string)
@ 2024-09-12 6:07 Emanuel Berg
2024-09-12 7:09 ` is OO a model that makes models? (was: Re: another day of cutting edge Elisp (read from a file to a string)) Emanuel Berg
2024-09-15 2:33 ` another day of cutting edge Elisp (read from a file to a string) Richard Stallman
0 siblings, 2 replies; 3+ messages in thread
From: Emanuel Berg @ 2024-09-12 6:07 UTC (permalink / raw)
To: emacs-devel
Here - don't mind eieio-specific syntax - or my own
`read-data' - what this does is actually to read the text in
a text file and pass it on as a string list (a list of
strings).
Trust me, I looked, but I never find anything. And not this
time either ;[ - but tell me, if and where it exists.
If it doesn't - hm, files, strings, the world's most powerful
editor - nobody thought about adding it since 1984?
39y 5m 23d
We also see in the below code, that while Lisp can indeed and
is often very cool and elegant, this doesn't
come automatically.
`buffer-substring-no-properties' must be the most ugly in all
of Elisp. Despite buffer being in the function name, one has
to specify (point-min) and (point-max), alltho that sounds
like a pretty reasonable default for no args. Also,
"no-properties", are we saying what we _don't_ want, now?
That said (about certain aspects), as for what I mentioned
initially, eieio (from 1995!) - that implements CLs CLOS -
that has been an absolute bliss, nothing short of amazing and
I used to spent 4 or 5 times the time on a single `defun' as
I now do on a whole class with 3-5 `cl-defmethod' - this
including initialization validation, defaults and so on - all
of which had to be manually in plain Elisp.
But it isn't just time - it is also complexity, with plain
Elisp it would have taken months and years to setup some kind
of framework to manage and reduce complexity, here it is
already available and, being the best or worst I don't know
but if you have it, you do use it and it does work. Wring what
I've been working on would have been impossible for me in
functional, and, to be honest, I think impossible or nearly so
for most people, including those with skills and experience.
eieio also solves many of the other problems I complained
about:
- modularity (no notion of a package, be it a convention or
real, but you don't need to care about that since OO is
modular by default - that's the whole idea - to couple data
with the functions that use them), and because of the extra
association with the name _there is no need for those
super-pesky and error prone local--fun-prefixes! that didn't
even denote anything real, it was just a convention - that
cost me I would say between 25% and 33% of all my errors).
- anti-MVC, "do everything in the buffer" - this very bad
tendency, that comes from two - let's call them "failed
states" - namely dynamic/special scope and the lack of
ability with pure functional style to store state and
actually _do_ stuff. Absolutely not a problem with eieio as
you on the contrary do everything in objects.
- I don't remember what more negative I said, but eieio has
solved that as well, the only thing it doesn't solve, and
maybe cannot solve, are the errors at the user level with
typos, "edit" errors (much around with parens here, cause
an error somewhere else; remove a sublist here, actually it
was the outer and not the inner; etc) also boredom and typos
because of Lisp's appreciation of overly
long-names-that-could-be-much-shorter, often typos happen
when you are unmotivated, it isn't interesting to type what
you are typing) - all in all, I'd say I have 5-7 times as
many typo/edit mistakes in Lisp, as I would have in
e.g. Python. Just my approximation about myself, and while
I may be more or less something than everyone else, I don't
think I'm so unique in this aspect, actually.
Lisp programmers are either hacker-angels with ridiculous
skills, or they aren't, in which case I think they have
normalized the amount of errors.
Do like this, work for 2h on random Elisp project that is
advanced, so not just a bunch of `alias' or anything like
that. Count how many errors you have in 2h! In other
languages, it is common that people who have spent decades
doing them have 1, 2 or 3 errors and hour writing code. But in
2h, I almost always have 10 errors, sometimes I have 20 errors
and it happens quite often I have 30 errors or more.
Do we have a module to give us stats on our own errors?
Like I said, I have typos, edit errors (those are an unknown
factor in most languages), and in particular I had insane
amounts of errors with the double--prefix convention - and
both ways! Either mine was wrong, backwards, or someone else's
were and I did it.
Anyway, here is the source:
(cl-defmethod read-file ((a ascii) &optional f dir)
(with-slots (name) a
(or dir (setq dir (file-name-concat bad-dir "data")))
(setq f (file-name-concat dir (or f (concat name ".txt")))))
(with-temp-buffer
(insert-file-contents f)
(let* ((lines (split-string
(buffer-substring-no-properties (point-min) (point-max))
"\n"))
(len (apply #'max (mapcar #'length lines))))
(read-data a (mapcar (lambda (l) (string-pad l len)) lines)))))
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 3+ messages in thread
* is OO a model that makes models? (was: Re: another day of cutting edge Elisp (read from a file to a string))
2024-09-12 6:07 another day of cutting edge Elisp (read from a file to a string) Emanuel Berg
@ 2024-09-12 7:09 ` Emanuel Berg
2024-09-15 2:33 ` another day of cutting edge Elisp (read from a file to a string) Richard Stallman
1 sibling, 0 replies; 3+ messages in thread
From: Emanuel Berg @ 2024-09-12 7:09 UTC (permalink / raw)
To: emacs-devel
> OO [...]
One last thing that is important in the old-school vs modern
OO discussion, that is in old-school OO one focused more on
"solving the problem by making a model of it" - that is hard
to argue with, as that is exactly what one is doing - both in
general, applying the OO model - but also in practice, solving
the particular problem at hand by setting up neat little
objects with cute traits.
However ...
The problem was the people got a little bit locked, and not
the least neurotic, about this, they thought they were
creating a copy of reality and if everything was copied to
perfection, the problem would solve itself automatically.
People spent a lot of time arguing where to put things for
example, and the argument was always refering to reality or
whatever model one was building, and _not_ where the element
would be useful to solve its task, and, by extension, the task
of the entire program.
So to counter this one started to focus on the model not being
a model in terms of similarity, necessarily, rahter the model
is a _tool_, can it be applied, and does it work? If so, put
things wherever you want, and wherever they are available and
ready to do their job.
I must say this makes more sense, and I recommend using, if
one uses eieio, `cl-defmethod' for _everything_ that has an
object, class or whatever mentioned if only one time - only
use `defun' when there is no explicit or implicit association
to any OO induced element.
Method. Write a `cl-defmethod'. If the object instance isnt'
used, replace the name with a dash. Leave it be for some time
(often you start using it during this period, I mean with an
instance so, you revert from the dash). But if that doesn't
happen, and it still just stands there with its gaping dash,
okay, turn it into a defun since it obviously was a mistake to
assume it had anything to do with this class or any object
instances thereof.
In practice, trust me when I say, very, very few defuns are
needed, and NO `defvar' (i.e. global or dynamic/special
variables) - not a single one - is needed even big project
with many files.
OO for Emacs, it is a small miracle I was unaware of existed
in this form. Like the OO of C++ only ... more cute, is the
best word to describe it. Much more cute <3
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: another day of cutting edge Elisp (read from a file to a string)
2024-09-12 6:07 another day of cutting edge Elisp (read from a file to a string) Emanuel Berg
2024-09-12 7:09 ` is OO a model that makes models? (was: Re: another day of cutting edge Elisp (read from a file to a string)) Emanuel Berg
@ 2024-09-15 2:33 ` Richard Stallman
1 sibling, 0 replies; 3+ messages in thread
From: Richard Stallman @ 2024-09-15 2:33 UTC (permalink / raw)
To: Emanuel Berg; +Cc: emacs-devel
[[[ To any NSA and FBI agents reading my email: please consider ]]]
[[[ whether defending the US Constitution against all enemies, ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]
I never wrote a function to read a file's contents into a string
because (1) it would not often be useful and (2) Emacs is bloated
already. If we added functions just because they would make sense, we
could add a lot of functions, but that usually would not make Emacs
better.
The reason it is not often useful is that usually when you read a file
having the contents in a buffer makes it convenient to operate on them.
--
Dr Richard Stallman (https://stallman.org)
Chief GNUisance of the GNU Project (https://gnu.org)
Founder, Free Software Foundation (https://fsf.org)
Internet Hall-of-Famer (https://internethalloffame.org)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-09-15 2:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-12 6:07 another day of cutting edge Elisp (read from a file to a string) Emanuel Berg
2024-09-12 7:09 ` is OO a model that makes models? (was: Re: another day of cutting edge Elisp (read from a file to a string)) Emanuel Berg
2024-09-15 2:33 ` another day of cutting edge Elisp (read from a file to a string) Richard Stallman
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.