:: Re: [DNG] C versus Python
Top Pagina
Delete this message
Reply to this message
Auteur: nick
Datum:  
Aan: dng
Onderwerp: Re: [DNG] C versus Python


O1bigtenor: about C versus Python.



I love and use both regularly and also I have taught both languages to undergraduates so hopefully I am in a position to give a balanced view.



The advantage of C is in raw speed and low level memory management (for example there is no garbage collector unless you implement one). Coupled with modern CPUs that will unroll your code and extract ILP (instruction level parallelism) it means that you can accomplish nearly any computation in C with simple code. You want Gaussian elimination? Simple code done the textbook way will perform reasonably well.



The advantage of Python is that it is easy to write and there are thousands of libraries available. Sure it is slow, but as long as you are doing some sort of standard activity such as digital filtering or matrix operations your program will spend hardly any time in the Python interpreter and most of the time in the pre built library (which is written in C or Fortran). If you go off the beaten track and need some algorithm that does a lot of "ifs and buts" while iterating over a big data set (or say a high volume of data arriving in real time) then Python will not do it well. But that's quite rare, and in those cases, use C.



So it's best to think of Python as the glue which connects the libraries that do the actual work. But that said, Python is capable of doing more or less what C can do, just slower and with less declarations / boilerplate code. In my opinion a good reason for beginners to learn Python is that it uses mostly C conventions, for example everything is zero based. Also the standard library is very C like, as it's just a thin wrapper over the underlying OS which is in C. Also you can do C like things with the struct and ctypes packages should you be inclined.



Another great thing about Python (3+) is that integers are bigints. So you can for example store a million digit number in an integer and everything will work as expected. But apart from being unbounded size they behave very like C integers, so are good for learning.



I'd probably hit Python first but you'll have to learn C eventually so why not do both?



Kind regards, Nick










>
> On 25 Oct 2024 at 6:38 pm, dng-request <dng-request@???> wrote:
>
>
> Send Dng mailing list submissions to
> dng@???
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng
> or, via email, send a message with subject or body 'help' to
> dng-request@???
>
> You can reach the person managing the list at
> dng-owner@???
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Dng digest..."
>
>
> Today's Topics:
>
> 1. another programming language question (o1bigtenor)
> 2. Re: another programming language question (karl@???)
> 3. Re: Lua (onefang)
> 4. flushling slim (Haines Brown)
> 5. Re: another programming language question
> (kc-devuan@???)
> 6. Re: Lua (onefang)
> 7. Re: flushling slim (tito)
> 8. Re: flushling slim (fraser kendall)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Thu, 24 Oct 2024 13:24:05 -0500
> From: o1bigtenor <o1bigtenor@???>
> To: Devuan ML <dng@???>
> Subject: [DNG] another programming language question
> Message-ID:
> <CAPpdf5-=TU7Qczj5Y+pWYLDMNJ3-q+tx=aazPF2Ep8s+ZybwJw@???>
> Content-Type: text/plain; charset="UTF-8"
>
> Greetings
>
> If I am asking too many questions of this kind of nature - - - please
> advise - - - my guru
> died some years ago (may even be known to some of you) so I have no
> place to get information - - so the questions continue (they've been
> going for a long time already - - - - grin!!).
>
> In the beginning stages of learning how to program.
>
> My mentor had advised that I seriously consider Python - - - but - - -
> looking at the slow processing
> time and the impetus provided by this group I have been working on learning C.
> (Now its slow going - - - - it seems that learning has become a going
> around in too many circles with not a lot of " write this - - - see
> this - - - means x and you use it for these reasons and in
> the following fashion. " - - - Maybe its too close to what I call
> monkey see monkey do kind of learning but I know it works AND the info
> sticks - - - maybe its the idea that counting now starts with zero
> instead of one has warped some other things - - - LOL.)
>
> So I remember hearing about Cython - - - - sounds like that really
> might be useful - - - you know a marriage between C and Python - - -
> so fast and you can get down close to the proc etc etc. Is this
> something to consider in trying to program microcontrollers and SoCs
> (microprocessors) to do things for me or is this better left until I
> get some fluency in C and then added?
>
> Please advise
>
> TIA
>
>
> ------------------------------
>
> Message: 2
> Date: Thu, 24 Oct 2024 22:04:43 +0200 (CEST)
> From: karl@???
> To: dng@???
> Subject: Re: [DNG] another programming language question
> Message-ID: <20241024200443.8393485CA2B5@???>
> Content-Type: text/plain
>
> olbigtenor:
> > Greetings
>
> Howdy!
>
> > If I am asking too many questions of this kind of nature - - - please
> > advise - - - my guru died some years ago (may even be known to some of you)
>
> Well gurus tend to die them also...
>
> > so I have no place to get information
>
> Ouch, you have us.
>
> ...
> > In the beginning stages of learning how to program.
> > My mentor had advised that I seriously consider Python
>
> It is good to know a script language, I like perl very much.
>
> > - - - but - - - looking at the slow processing time
>
> If python solves your problem, it will be a much faster processing
> the having no solution. At least you could build a prototype
> implementation and test out the problem more quiokly than doing all
> the nitty-gritty handiwork in C.
>
> > and the impetus provided by this group I have been working on learning C.
> > (Now its slow going - - - - it seems that learning has become a going
> > around in too many circles with not a lot of " write this - - - see
> > this - - - means x and you use it for these reasons and in
> > the following fashion. " - - - Maybe its too close to what I call
> > monkey see monkey do kind of learning but I know it works AND the info
> > sticks - - -
>
> It's good to know ones best kind of learning, from what I heard, some
> learn by seeing, some by hearing, and some by feeling (tactile).
>
> > maybe its the idea that counting now starts with zero
> > instead of one has warped some other things - - - LOL.)
>
> Well it isn't that counting starts with zero, it is that to go to
> number 2, you have to add one to number 1, soo think it more as an
> offset than a count:
>
> int arr[10]; // 10 is the count, the number of elements.
>
> int start = arr[0]; // i.e. at offset 0 of arr, there is where start is
> int end = arr[9]; // i.e. att offset 9 of arr, there is the end
> int count = sizeof(arr)/sizeof(int); // this is a count, the number of elements
>
> > So I remember hearing about Cython - - - - sounds like that really
> > might be useful - - - you know a marriage between C and Python - - -
> > so fast and you can get down close to the proc etc etc. Is this
> > something to consider in trying to program microcontrollers and SoCs
> > (microprocessors) to do things for me or is this better left until I
> > get some fluency in C and then added?
>
> there doesn't seem to be any cpython for mcus available:
> https://en.wikipedia.org/wiki/Cpython#Distribution
>
> > Please advise
>
> If you are at ease with python you are not going to do anything
> advanced, why not just stick with micropython and use a mcu that
> supports it.
> At least you can start with micropython and if and when it fails
> to deliver, try some other language.
> In the meantime try out a few languages and see if they suits you.
>
> Regards,
> /Karl Hammar
>
>
>
>
> ------------------------------
>
> Message: 3
> Date: Fri, 25 Oct 2024 08:18:21 +1000
> From: onefang <onefang_devuan@???>
> To: dng@???
> Subject: Re: [DNG] Lua
> Message-ID:
> <20241024221821.z2euebcpufxpuxei@???>
> Content-Type: text/plain; charset=iso-8859-1
>
> On 2024-10-24 11:49:44, Didier Kryn wrote:
> > Le 24/10/2024 ? 04:24, onefang a ?crit?:
> >
> > Sooo, I can write Lua in any language. B-)
> >
> > ??? AFAIU Lua is one of these few intrepreted languages which allow to add
> > scripting capability to programs written in other languages, like was the
> > IBM Rexx and the more widespread TCL. I mean that the interpreter can be
> > invoqued from within the application and invoque application-provided
> > procedures. TCL is more primitive but it comes with a graphical tool-kit.
> > Any idea of how to create a GUI with Lua?
>
> I have used ARexx on the Amiga, which is based on Rexx.
>
> The languages I picked for my hello world example was the result of
> running the file command over /usr/bin to see what scripting languages
> are actually being used there. TCL did pop up a few times, but I didn't
> quickly find an example hello world that didn't involve GUI elements.
> Never used TCL. So in theory this method of mine will work with TCL to
> get a GUI into Lua. Contributions in other languages welcome.
>
> I'm well aware of how you can hook Lua up to other languages, that's one
> of the reasons I love it. C code can easily include a Lua interpreter, a
> tiny bit of code. Then C can call Lua, and Lua can call C.
>
> I was maintainer of the Lua interface for the Enlightenment Foundation
> Libraries, which is the basis of the Enlightenment window manager. So I
> have used that to create GUIs in the past, with a mixture of C and Lua.
>
> I suspect the PHP example didn't work coz the example I copied from might
> have been expecting a web server environment, with a web browser front
> end, not just dumping text to stdout. But that might get you a web based
> GUI.
>
> LSL, Linden Scripting Language, is a C like scripting language for Second
> Life and OpenSim virtual worlds. I wrote C code that translates that
> into Lua, and runs it under LuaJIT. LSL has some very basic GUI
> elements, but it can control the 3D world and respond to clicks on
> objects and such. I barely count it as GUI though. lol
>
> So plenty of ideas. I'm even considering writing my own, but not today.
>
> --
> A big old stinking pile of genius that no one wants
> coz there are too many silver coated monkeys in the world.
>
>
> ------------------------------
>
> Message: 4
> Date: Thu, 24 Oct 2024 18:47:40 -0400
> From: Haines Brown <haines@???>
> To: dng@???
> Subject: [DNG] flushling slim
> Message-ID: <ZxrOjHTDApDijf1p@???>
> Content-Type: text/plain; charset=us-ascii
>
> I need to get rid of slim "display manager" so that boot tOresents a
> cli text log in.
>
> # update-rc.d -f slim disable 2
>
> This has no effect.
>
> I go to /etc/X11/default and comment the line /usr/bin/slim
> But this had no effect.
>
> My goal is to have startx start fluxbox automatsically. I suppose I
> could uninstall slim, but then I fear I'm just get the default decvuan
> window manager.
>
> Then I do $ startx fluxbox I get what suppose is the devuan default
> winwow manager (a grey desktop with devuan spiral lower right). It
> blocks starting fluxbox.
>
> I have no ~/.bash_profile or ~/.xinitrc
>
>
> --
> Haines Brown
>
>
> ------------------------------
>
> Message: 5
> Date: Fri, 25 Oct 2024 00:36:30 +0100 (GMT+01:00)
> From: kc-devuan@???
> To: dng@???
> Subject: Re: [DNG] another programming language question
> Message-ID: <bd50612d-acd9-42e9-946a-f04989ed1b84@???>
> Content-Type: text/plain; charset=UTF-8
>
> 24 Oct 2024 21:05:02 karl@???:
>
> > there doesn't seem to be any cpython for mcus available:
> > https://en.wikipedia.org/wiki/Cpython#Distribution
>
> I can't bring myself to recommend it but there is micropython.
>
>
> ------------------------------
>
> Message: 6
> Date: Fri, 25 Oct 2024 11:00:15 +1000
> From: onefang <onefang_devuan@???>
> To: dng@???
> Subject: Re: [DNG] Lua
> Message-ID:
> <20241025010014.6coikgk4n4db5bjs@???>
> Content-Type: text/plain; charset=us-ascii
>
> On 2024-10-24 12:24:40, onefang wrote:
> > Could be possible to get it to deal with compiled languages as well, but
> > think I'll dodge that rabbit hole for now.
>
> OK, so I cheated, but now it can do C. B-)
>
>
> __[[#!/usr/bin/tcc -run
> #include <tcclib.h>
>
> int main()
> {
> printf("Hello world from C.\n");
> return 0;
> }
> ]]:log():show():Do()
>
>
> Obviously tcc needs to be installed, it's a tiny C compiler.
>
> I may tackle assembler some day. lol
>
> --
> A big old stinking pile of genius that no one wants
> coz there are too many silver coated monkeys in the world.
>
>
> ------------------------------
>
> Message: 7
> Date: Fri, 25 Oct 2024 09:23:48 +0200
> From: tito <farmatito@???>
> To: dng@???
> Subject: Re: [DNG] flushling slim
> Message-ID: <20241025092348.4710ab78@devuan>
> Content-Type: text/plain; charset=US-ASCII
>
> On Thu, 24 Oct 2024 18:47:40 -0400
> Haines Brown via Dng <dng@???> wrote:
>
> > I need to get rid of slim "display manager" so that boot tOresents a
> > cli text log in.
> >
> > # update-rc.d -f slim disable 2
> >
> > This has no effect.
>
> Maybe:
> insserv -r slim
>
> -r, --remove
> Remove the listed scripts from all runlevels.
>
> Hope this helps,
> Ciao Tito
>
> > I go to /etc/X11/default and comment the line /usr/bin/slim
> > But this had no effect.
> >
> > My goal is to have startx start fluxbox automatsically. I suppose I
> > could uninstall slim, but then I fear I'm just get the default decvuan
> > window manager.
> >
> > Then I do $ startx fluxbox I get what suppose is the devuan default
> > winwow manager (a grey desktop with devuan spiral lower right). It
> > blocks starting fluxbox.
> >
> > I have no ~/.bash_profile or ~/.xinitrc
> >
> >
>
>
>
> ------------------------------
>
> Message: 8
> Date: Fri, 25 Oct 2024 08:38:26 +0100
> From: fraser kendall <lfs.mailing@???>
> To: dng@???
> Subject: Re: [DNG] flushling slim
> Message-ID: <20241025083826.5f4190be@Latitude>
> Content-Type: text/plain; charset=US-ASCII
>
> On Thu, 24 Oct 2024 18:47:40 -0400
> Haines Brown via Dng <dng@???> wrote:
> >
> > I go to /etc/X11/default and comment the line /usr/bin/slim
> > But this had no effect.
>
> I replace that entry with:
>
> echo "/bin/true" > /etc/X11/default-display-manager
>
> and it works for me.
>
>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> Dng mailing list
> Dng@???
> https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng
>
>
> ------------------------------
>
> End of Dng Digest, Vol 121, Issue 57
> ************************************
>