News for hackers. Stuff that matters.
Re:Ask HN: What are you learning? by tomxor on Sunday April 05, 2020 @12:39PM (#22786577)
... Don't laugh: C

I learnt programming mainly through various scripting languages, some of which had some relatively simple visual output available, which I personally found invaluable for learning and visualizing.

I realized that better visual output was the main thing holding me back from doing more in C since there are so many options, often complex, involving much boilerplate. So my mini project is essentially exploring the simplest, most minimal possible ways of drawing pixels on the screen in Linux.

So far tried fbdev (but doesn't work well with X), now playing with XCB.

Re:Ask HN: What are you learning? by idoby on Monday April 06, 2020 @02:50AM (#22791413)
Why would I laugh?

I've done a lot of C programming over the years and I still consider it one of the most elegant languages I've had the opportunity to work with. With the right skillset, you can be as productive as a programmer of any other language or system.

And it's great to see where some of the things we take for granted in programming, come from.

If you want to draw pixels, give Cairo a try. It's fun to use!

Re:Ask HN: What are you learning? by tomxor on Monday April 06, 2020 @09:10AM (#22793386)
Nice to hear from people still enthusiastic about C :)

Thanks for the suggestion, I hadn't considered Cairo, for some reason I thought it was only for SVG, maybe from it's use in Firefox. I will try it out once I get out of XCB territory.

Re:Ask HN: What are you learning? by zetalemur on Sunday April 05, 2020 @01:12PM (#22786838)
> So far tried fbdev (but doesn't work well with X), now playing with XCB.

Another idea would be to use SDL which essentially provides functionality to make windows, draw pixels and handle input/output. If you do not want to use any library at all and do not mind low "resolution", you could use your terminal as window and regard characters as pixels. Sure, there is the curses library to abstract away different terminals, but if you do not care about platform independence you can just directly write escape sequences to the terminal.

Re:Ask HN: What are you learning? by tomxor on Sunday April 05, 2020 @01:24PM (#22786907)
I was indeed trying to avoid the big libraries, since this is just for personal use I don't care about cross platform which allows me to escape these potentially - I may well end up back at the SDL + OpenGL level later when features or performance are a concern.

My current goal is to find a balance of least dependencies and least boilerplate to draw a pixel buffer so i can play with C, nothing more. Once I can do that without lots of fluf then i may be attracted to more advanced or complex methods later on when performance is desirable.

I have done some visual things with the console and printf alone in the past which gave me a taste of C, but now I want some real pixels :)

Re:Ask HN: What are you learning? by mntmoss on Sunday April 05, 2020 @04:14PM (#22788296)
You may want to try raylib. It's written by a teacher who uses it in the classroom and geared for this kind of "let me code games in C but with only one dependency" goal. It does more than you need but that's a common theme of useful libraries.
Re:Ask HN: What are you learning? by tomxor on Sunday April 05, 2020 @04:23PM (#22788380)
Thanks, that sounds about right, i'll take a look.
Re:Ask HN: What are you learning? by kovac on Sunday April 05, 2020 @08:45PM (#22790009)
Have you tried A allegro5? Any take on which is better? I've tried both, but I'm too much of a newbie to have a reasonable opinion. Thinking of getting back on to one of the two.
Re:Ask HN: What are you learning? by jfkebwjsbx on Sunday April 05, 2020 @07:19PM (#22789558)
Then you should be using X11 directly!
Re:Ask HN: What are you learning? by tomxor on Sunday April 05, 2020 @08:03PM (#22789797)
My goal is to attain a balance of least dependencies and boilerplate. From what I've read so far it seems that implementing xclient protocols directly would require considerably more boilerplate than using XCB, (and my understanding is that XCB is just that: a generic xclient implementation and nothing more).

Please do elaborate if I'm wrong though! I would be delighted if it's possible to implement a simple subset minimally purely for displaying a pixel buffer without XCB?

Re:Ask HN: What are you learning? by CmdrKrool on Monday April 06, 2020 @02:08AM (#22791249)
I'm not necessarily recommending you go this route in general, but this is a fantastically actionable article for going deep on various Linux graphics APIs including X11 right on the socket: http://betteros.org/tut/graphics1.php
Re:Ask HN: What are you learning? by tomxor on Monday April 06, 2020 @09:20AM (#22793450)
Yes, I really like this article, I used it to get going with fbdev before I moved on to XCB, but only skimmed the remainder since it was avoiding libraries completely it was getting a little verbose (although on second thought DRM doesn't look too bad, and also I missed libdrm should probably see how much that can do).

Just realized now revisiting this that the author also showed how to directly implement xclient! the example is rather large confirming my suspicions RE parent comments.

Re:Ask HN: What are you learning? by jfkebwjsbx on Monday April 06, 2020 @05:59AM (#22792204)
I meant using Xlib, the client library for X11, which is going to always be available if you are using X! You can of course implement the library parts yourself, but that is more boilerplate.
Re:Ask HN: What are you learning? by tomxor on Monday April 06, 2020 @09:00AM (#22793299)
XCB is actually lower level than xlib, in that sense it is more directly using X11 because unlike xlib it only really implements the client protocol and wraps it up into an interface.

I was however planning on trying out Xlib anyway on my path of exploration from simplest/lowest level to complex/higher level libraries: fbdev, DRM < DirectFB, libdrm < XCB < Xlib < SDL et al.

Re:Ask HN: What are you learning? by DizzyDoo on Sunday April 05, 2020 @12:52PM (#22786662)
Out of interest, why would people laugh at someone learning C? I know plenty of people using C in all manner of domains, choosing it over C++ or Rust for fair and sensible reasons - I'm not a C person myself, but it certainly seems extremely useful to have in the toolkit!
Re:Ask HN: What are you learning? by tomxor on Sunday April 05, 2020 @01:04PM (#22786767)
I want to learn C not (only) because I think it's useful, but because I think I might like it. I have a particular interpreted language that I like, enjoy and know inside out, now I want to know a compiled one in a similar way.

To answer your question: I get the impression from various tech news on "hot new languages" that C is the incumbent systems language that people put up with but don't really love, and yet I want to try and love it. I've developed a taste for minimalism, simplicity and a degree of brevity in programming, I have a feeling I might find C more suited to me than C++, Rust, Go, Java etc for this reason despite the lack of "modern" features.

Re:Ask HN: What are you learning? by juped on Monday April 06, 2020 @02:31AM (#22791341)
I love C. Lots of people do.
Re:Ask HN: What are you learning? by wyck on Sunday April 05, 2020 @01:03PM (#22786762)
I've noticed this a lot on hackernews, there is an apprehesion to say certain things as though there is some sort of pedigree or gating when discussing topics, especially when it's personal...there isn't.

Case in point: The comment below mine...

Re:Ask HN: What are you learning? by selfish-duck on Sunday April 05, 2020 @05:28PM (#22788879)
I started coding 10 years ago (damn I just figured that...) learning C at my engineering school for 2 years. Never had to use it ever since (mostly working front-end and webAPIs) but I'm still glad I studied it to learn the programming foundations. I would probably choose Rust or Go today though.
Re:Ask HN: What are you learning? by MaxBarraclough on Monday April 06, 2020 @07:25AM (#22792714)
> why would people laugh at someone learning C?

I suppose because of the perception that many programmers already know C. Which is true, but only some fraction know it well, which is far more important in C than in most modern languages.

[dead]
Re:Ask HN: What are you learning? by tomnj on Sunday April 05, 2020 @04:51PM (#22788613)
There are plenty of reasons to still learn C even if better alternatives exist for most new projects. There’s so much important software out there in C (and C++), for example the Linux kernel.
Re:Ask HN: What are you learning? by tomnj on Sunday April 05, 2020 @04:59PM (#22788688)
And C is still king in many domains, eg embedded development.
Re:Ask HN: What are you learning? by wyck on Sunday April 05, 2020 @01:06PM (#22786793)
whoosh..