Rather than a bash script, this is what I use to produce my "status bar", which is updated every second and looks like this:

Code:

Load: 0.46 RAM: 32 MiB Swap: 0 MiB Thu Jan 24 00:00:18

This is the code. I wrote it for my use only. It's not very portable, flexible, or idiot-proof; it doesn't include error checking and the other things good code should have before it's distributed. But it's far more efficient than a shell script (the normal way of doing it). It also never closes the display, but that doesn't matter because I always close X when close dwm. To be "correct", I suppose the pointer to the XDisplay should be a global variable, so it could be closed by signal trapping, but I hate global variables and that scenario will probably never occur, and it's a one-time 4-byte leak if it did occur, so fuck it.

My post wasn't meant to be a joke, I'm serious! Especially because I'm digging into C anyway at the moment and I want to code many different things from gtk-graphic widget stuff for my desktop (I always wanted a binary clock but all I've found in the portage tree or elsewhere aren't my taste, so its a good programming exercise payed with the exact style I want) to system programming. I mean one important thing of Linux is the availability of the source and if one don't modify/ play with it, it would be a waste (at least for people that work with computers or just like to play with them) and without C there isn't much to do, therefore I have another playground with practical consequences and move towards my own desktop..

Quote:

If I want to be notified of something, I'll code that in to my own status bar (which is fed by an efficient little C application I wrote).

++

Quote:

But it's far more efficient than a shell script (the normal way of doing it

do you think it would be better to code as much as possible in C and avoid python/bash-scripts?

thanks to you both for the code examples, I will try them today! Do you know "stumpwm" ? I didn't try it but could be also cool..._________________"I want to see gamma rays! I want to hear X-rays! Do you see the absurdity of what I am? I can't even express these things properly because I have to conceptualize complex ideas in this stupid limiting spoken language!"

Shell script (e.g., BASH) is fine for most purposes and if there's a utility or tool already existing which that does exactly what you want, just calling it from a script is smart; why reinvent the wheel?

Python is much faster than shell and fast enough for almost any end-user purposes. There are entire window managers written in Python and languages like it. Python is much higher-level than C/C++, so you can get a lot more done in it with a few lines of code. It's got all kinds of powerful built-in capabilities, so you don't have to make use of external libraries as much. In a GNU/Linux distribution like Gentoo, where python is a core part of the system (Portage is written mostly in Python, for example), it's already on your system and may well need to loaded at various times, so there's some overlap of needs there. (In other words, in my opinion, it's better to use Python than something else you're not already using, like Ruby or some other interpreted language).

Like Prenj suggested, a good approach is to write what you want in shell (BASH unless you've changed yours) or an interpreted language (e.g., Python), and then, if there is significant benefit to doing so, you can write it in C, C++ or another compiled language (although, as you've noted, on Linux it makes sense to do things in C/C++ that are going to interact with the system, use a C-based widget set, and so on.).

To be honest, C is overkill for most things a user would want to do, but extending your desktop environment can be an exception to that, if it's a function that's constantly running or very frequently used.

Also, be advised that I'm not a computer scientist, programmer, or sysadmin like many of the guys in here: I'm just a hobbyist; so I may be telling you a lot of stupid crap and you can almost certainly get better advice from almost anybody. _________________Deja Moo: the feeling that you've heard this bull before

Shell script (e.g., BASH) is fine for most purposes and if there's a utility or tool already existing which that does exactly what you want, just calling it from a script is smart; why reinvent the wheel?

ok.. but mostly programs that you didn't wrote by yourself don't do exactly what you want. But maybe it's better to code new things then just rewrite python-scripts in C.

Quote:

There are entire window managers written in Python and languages like it. Python is much higher-level than C/C++, so you can get a lot more done in it with a few lines of code. It's got all kinds of powerful built-in capabilities, so you don't have to make use of external libraries as much. In a GNU/Linux distribution like Gentoo, where python is a core part of the system (Portage is written mostly in Python, for example), it's already on your system and may well need to loaded at various times, so there's some overlap of needs there. (In other words, in my opinion, it's better to use Python than something else you're not already using, like Ruby or some other interpreted language).

what is the reason that portage was written in python and that gentoo is so focused on python? I've heard that there is paludis which is written in C/C++..

Quote:

Like Prenj suggested, a good approach is to write what you want in shell (BASH unless you've changed yours) or an interpreted language (e.g., Python), and then, if there is significant benefit to doing so, you can write it in C, C++ or another compiled language (although, as you've noted, on Linux it makes sense to do things in C/C++ that are going to interact with the system, use a C-based widget set, and so on.).

To be honest, C is overkill for most things a user would want to do, but extending your desktop environment can be an exception to that, if it's a function that's constantly running or very frequently used.

so the reason for using python is because it's nearly as fast as C and it's more comfortable to code in a higher-level language? Although I see the advantages I don't like it when you go to far away from the hardware, because the source is then more and more different from the actual program. I know one should know as many languages as possible but I hate it when I'm for example very familiar with C-syntax and then I write an octave-code, and although the syntax is similar to C, it's sometimes exhausting to recall all the small differences and it's a bit more error-prone.

Quote:

Also, be advised that I'm not a computer scientist, programmer, or sysadmin like many of the guys in here: I'm just a hobbyist; so I may be telling you a lot of stupid crap and you can almost certainly get better advice from almost anybody.

ok, thats the reason why you can afford it to read so much about politics no seriously, I think if you tell me bullshit then someone of those pros would step in and if not I will recognize it someday and to make mistakes is good for the learning curve. Moreover hobbyist are sometimes better then pros _________________"I want to see gamma rays! I want to hear X-rays! Do you see the absurdity of what I am? I can't even express these things properly because I have to conceptualize complex ideas in this stupid limiting spoken language!"

Last edited by LoTeK on Sun Feb 03, 2013 1:54 am; edited 1 time in total

I was suggesting writing stuff in Python, because it's fast to develop in, portable, and has amazing pool of toolkits and libraries for almost everything.

It is fast enough for lots of uses, but if/when you come to the point that something isn't fast enough in python, you can write that slow piece of code in C, and execute it within the existing python code.

That way you don't have to re-write everything, nor do you have to use C all the way, which IS time-consuming and it takes away the focus from developing what you want, to having to fiddle with all the crufty bits that you HAVE to do, in order to make it work.

Also, it teaches you the most important lesson, and that is just because something is written in C, it doesn't mean it has to be faster then something written in Java or Python. It may not sound true, if you only think about simple programs, where you would basically write the same stuff in Python or C.

But it has to do with writing with wrong paradigm in mind, like do you use asynchronious I/O or do you poll and waste CPU time on that. Or do you read/write to a disk, or do you keep stuff in memory, and occasionally sync when you run out of space.

So my advice would be, if you're just gonna fiddle, and write some for-loops, open files and such, write it in both languages, if you want to learn. But if you are gonna make something more complex, read up on different ways of designing things (read about Design Patterns), write it in Python first, cos you can follow a pattern easier from higher-level language, and then when you feel bold enough, do it in C, or parts of it.

I know, I've said this because I thought about rewriting stuff in C, but it's maybe a waste of time...

Quote:

I was suggesting writing stuff in Python, because it's fast to develop in, portable, and has amazing pool of toolkits and libraries for almost everything.

ok, I don't know python yet (I think its similar to octave ?!), but so is C (maybe not as fast to develop compared to python, I don't know)

Quote:

That way you don't have to re-write everything, nor do you have to use C all the way, which IS time-consuming and it takes away the focus from developing what you want, to having to fiddle with all the crufty bits that you HAVE to do, in order to make it work.

This was a main reason for betrand meyer to develop Eiffel (simple syntax that allow one to focus on the problem and not the language). I see the advantages of this approach, but maybe there are contexts that require "ugly" low-level handling. The problem I have with the "focus on the problem and not the language or hardware" approach is that in computer science or engineering you should WANT to bother with machines and bits etc otherwise you should become a mathematician then you don't have to bother with such things at all, or do you disagree?

Quote:

Also, it teaches you the most important lesson, and that is just because something is written in C, it doesn't mean it has to be faster then something written in Java or Python. It may not sound true, if you only think about simple programs, where you would basically write the same stuff in Python or C.

yes I've heard of that (in some tests C/C++ programs were even the slowest, but I don't remember in what context)

Quote:

So my advice would be, if you're just gonna fiddle, and write some for-loops, open files and such, write it in both languages, if you want to learn. But if you are gonna make something more complex, read up on different ways of designing things (read about Design Patterns), write it in Python first, cos you can follow a pattern easier from higher-level language, and then when you feel bold enough, do it in C, or parts of it.

ok sounds reasonable _________________"I want to see gamma rays! I want to hear X-rays! Do you see the absurdity of what I am? I can't even express these things properly because I have to conceptualize complex ideas in this stupid limiting spoken language!"

haha why? because my english is not very shakespeare style? _________________"I want to see gamma rays! I want to hear X-rays! Do you see the absurdity of what I am? I can't even express these things properly because I have to conceptualize complex ideas in this stupid limiting spoken language!"

Ok, thanks very much
pretty close.. from switzerland.._________________"I want to see gamma rays! I want to hear X-rays! Do you see the absurdity of what I am? I can't even express these things properly because I have to conceptualize complex ideas in this stupid limiting spoken language!"

*looks around for dmitchell*_________________At the heart of the durability of mass schooling is a brilliantly designed power fragmentation system which distributes decision-making so widely among so many different warring interests that large-scale change is impossible to those without a codebook.

why? do you mean from a theoretical position? In the sense that it's C with classes, so not really a "clean O-O" language like eiffel but also way more complicated than C?

Although I'm no expert I think C++ is way better than java or even C# (we need a vomit icon ) and because python is a scripting language you can't do any low-level stuff..._________________"I want to see gamma rays! I want to hear X-rays! Do you see the absurdity of what I am? I can't even express these things properly because I have to conceptualize complex ideas in this stupid limiting spoken language!"

... and because python is a scripting language you can't do any low-level stuff...

False.
Making C/C++ extension modules for Python or calling C functions is actually quite easy with Python.
And the Python standard library provides modules for almost any common system call, so you can conveniently work with pts, sockets, threads and other stuff in Python, with the nice bonus of having e.g. sockets as objects, so you don't have to pass a socket pointer to each call. Of course, these modules are implemented in C, so it's almost as fast.

Ok, I get it, I have to learn python _________________"I want to see gamma rays! I want to hear X-rays! Do you see the absurdity of what I am? I can't even express these things properly because I have to conceptualize complex ideas in this stupid limiting spoken language!"

... and because python is a scripting language you can't do any low-level stuff...

False.
Making C/C++ extension modules for Python or calling C functions is actually quite easy with Python.
And the Python standard library provides modules for almost any common system call, so you can conveniently work with pts, sockets, threads and other stuff in Python, with the nice bonus of having e.g. sockets as objects, so you don't have to pass a socket pointer to each call. Of course, these modules are implemented in C, so it's almost as fast.

I'm just laying some bait for dmitchell you guys, we already know how bad C++ is but we have to make sure everyone knows._________________At the heart of the durability of mass schooling is a brilliantly designed power fragmentation system which distributes decision-making so widely among so many different warring interests that large-scale change is impossible to those without a codebook.

I've tried dwm now and I like it, but I don't know how to fix this error:

Code:

dwm: missing font set ISO8859-1

do you had the same problem? because your config.h doesn't include anything else?! I've tried to include some fonts headers from /usr/include to dwm.c but it hasn't changed anything...
in /etc/locale.gen I've uncommented only en_US ISO-8859-1 and en_US.UTF8 UTF 8.

btw, I've started to use anonymous-pro, very nice font for coding, one can see a clear difference between ":" , ";" and the different brackets.._________________"I want to see gamma rays! I want to hear X-rays! Do you see the absurdity of what I am? I can't even express these things properly because I have to conceptualize complex ideas in this stupid limiting spoken language!"

I've tried dwm now and I like it, but I don't know how to fix this error:

Code:

dwm: missing font set ISO8859-1

do you had the same problem? because your config.h doesn't include anything else?! I've tried to include some fonts headers from /usr/include to dwm.c but it hasn't changed anything...
in /etc/locale.gen I've uncommented only en_US ISO-8859-1 and en_US.UTF8 UTF 8.

btw, I've started to use anonymous-pro, very nice font for coding, one can see a clear difference between ":" , ";" and the different brackets..

and my font won't get loaded (with openbox it works)_________________"I want to see gamma rays! I want to hear X-rays! Do you see the absurdity of what I am? I can't even express these things properly because I have to conceptualize complex ideas in this stupid limiting spoken language!"

…if you wrote those comments yourself, it's time to hand in your man-card.

No seriously, those are actually really good. cat >> .Xresources I say.

BoneKracker wrote:

Rather than a bash script, this is what I use to produce my "status bar", which is updated every second and looks like this:

Code:

Load: 0.46 RAM: 32 MiB Swap: 0 MiB Thu Jan 24 00:00:18

This is the code. I wrote it for my use only. It's not very portable, flexible, or idiot-proof; it doesn't include error checking and the other things good code should have before it's distributed. But it's far more efficient than a shell script (the normal way of doing it). It also never closes the display, but that doesn't matter because I always close X when close dwm. To be "correct", I suppose the pointer to the XDisplay should be a global variable, so it could be closed by signal trapping, but I hate global variables and that scenario will probably never occur, and it's a one-time 4-byte leak if it did occur, so fuck it.

To be honest, C is overkill for most things a user would want to do, but extending your desktop environment can be an exception to that, if it's a function that's constantly running or very frequently used.

Yeah that reminds me of when I was still using wmii. I mean I really liked it for what it did, it came with nice defaults and I also liked the "programmable configuration".
But as much as I liked it's 9p interface, when I realised that I was effectively running a shellscript that started a python program that read the user input and used a python library to write commands to a file that would be handeled by a 9p server that would interpret the command I felt that this might just be a little too much overhead for opening a terminal.