nixers
The impracticality of c & projects - Printable Version
+- nixers (https://nixers.net)
+-- Forum: Development & Graphics (https://nixers.net/Forum-Development-Graphics)
+--- Forum: Programming On Unix (https://nixers.net/Forum-Programming-On-Unix)
+--- Thread: The impracticality of c & projects (/Thread-The-impracticality-of-c-projects)


The impracticality of c & projects - Houseoftea - 23-08-2015

Hey gang,

I've been playing around with c, beginning stages of course. I've been having a great time making various little text games and conversion programs.

I have two questions for the senior devs out there.

First: I've been Reading a lot and people keep saying c is impractical for modern projects. Useful only on embedded systems or for kernels. Is this because its a low level language or its lack of objects or are they wrong?

Second: I was considering playing around with swm, I was going to fork and play with wmutils but poor z3bra and dcat might die of shame if they saw the damage my novice code would do on those beautiful tools.

My question is, are there any other little projects you've come across on github that would be worth checking out?

And because I don't like to ask without giving a little here are some projects I dug up that you all might find interesting:

https://github.com/gorel/C-Poker-AI
Texas hold em, written in c

https://github.com/gkbrk/SirLogsalot
Irc bot to record conversations

https://github.com/ErikStaats/adventure
Text adventure written in c

Just some things to think about.

Also inb4 venam closes this ;)


RE: The impracticality of c & projects - cjm - 23-08-2015

C is a great language for many reasons. As a second year software dev student C is my favourite language for a couple of reasons.

* It's simplicity is its strong suit. C is often said to be one of the harder languages due to the fact that it is low level. Although I would argue that it is one of hte better languages to start beginners off with. This is because it allows one to write simple code, but have to maintain a level of understanding of the underlying mechanisms of the computing environment. C has very few core elements but those elements come together in a way that is eloquently simple to understand when you know what you are doing (the same could be said about the UNIX development environment :-)). The beauty of C is that once you learn it, the program structure itself enforces good coding practice to maintain readability. And its not a forced trope of the language in a way that python or ruby's is. Mind you I know that one has to _want_ to write clean code when it comes to C, but the fact that you have to carefully analyze each step you make can become a great asset in future programming.

* Another area is that is it is everywhere. I mean you can put a C compiler on a piece of metal. That portability is a leading factor in why it has been around for so many years now. With the new internet of things, I believe embedded devices will still run C as long as embedded devices stand.


As you can see C is one of my favourite language. I love writing code in it to be honest. Don't get me wrong there are tons of great languages out there, but C will always hold a special place in my heart.

Overall its about whats best for the job and what tool you are most comfortable with. I think computing in general is about choice and freedom, so writing software in your favourite language is your own prerogative. I just love being able to read code and peoples thoughts patterns.

As for projects:

https://github.com/rmccullagh/libmutablestring This is a cool small library that is fun to read through. I found it today!

http://cvsweb.openbsd.org/cgi-bin/cvsweb/ This is the OpenBSD repo, any utility they create is always worth a read through.


RE: The impracticality of c & projects - z3bra - 24-08-2015

C is a special language. It's one of the oldest programming language, it's low level and used everywhere.
It's especially true in the unix world, where even the filesystem is shaped around it (/lib, /include, environment variables, ...).

But C is hard. And not only because of the syntax. Nobody really care about the syntax, it's just another set of keywords to get used to.
C is hard because of it's pedantism, and its mulitple way to screw things up.
When you write in C, you're coding without a safety net. You get no out-of-bound error checking, you can overwrite anything in memory, you can't "catch" errors, or fix them "later".
When you make a mistake, the program either crash or misbehave (remember heartbleed or shellshock?)

Most scary bugs happens in code written in C, and everytime it does, freshmen be like: "That'd never happen with haskell".
Still, most softwares are written in C. Coreutils, libressl, nginx, linux, systemd, gpg, ... You name it.

C is, and will remain the most used language IMO, because of the freedom it gives you when you write. The syntax doesn't matter, you can manipulate the memory however you want, you're assured that the environment will be setup for it, and there are a shitons of tools to work with it.

Because of its simplicity, you can create complex data structures, shape it however you want, and manipulate it to your likings. But some programmers don't like this "freedom" (as in, you're free to make bugs), and thus prefer languages that will prevent you from making errors. Some people just don't need the freedom C gives, and it's perfectly fine. But some people prefer shitting over it without even trying to understand why C is used this much. Just ignore these people.

So to answer your first question: NO. C isn't impractical for modern languages. It's just better suited for some project, like any language.

For your second question... Dude, play with wmutils however you want! I'm just affraid you won't be able to have a lot of fun with it, because of how simple the tools are.
If you want to play with a few projects, I'd suggest 2bwm. It's well written, and has a huge potential to implement new features.

A good way to play with it is to take the Euler project, and go as far as you can. exercises 1 to 8 are a good start. You could then start rewriting some of your shell scripts in C to optimise the perfs and similar things.
After you're done with it, just search for cool libraries and create tools using them (termbox, inotify, libcaca, ...).

Also, read other's people code, it's the best learning source.

BONUS

PS: as for the last line:
(23-08-2015, 09:41 PM)Houseoftea Wrote: Also inb4 venam closes this ;)

That's lame.


RE: The impracticality of c & projects - venam - 24-08-2015

The impracticality of c & projects
Let's check the definition:

Quote:1) Unwise to implement or maintain in practice.
2) Incapable of dealing efficiently with practical matters, especially finances.

I would agree with the second definition but not the first.

C, like all programming languages, has its place and usage.
I won't explain what it's good for because it has already been done in this thread.
Let me just add this; You'll soon get the hang of many languages and libraries and you'll be able to discern in what situation one language is more appropriate than another. It will depend on factors such as the framework, environment you are working with, your needs, your time, etc..


Unfortunately, unlike scripting languages, C programs take time to polish and secure which makes it impractical in today's ever moving world. It needs investment! Companies have to make trade-offs to be able to use C.


(24-08-2015, 07:38 AM)z3bra Wrote: PS: as for the last line:
Quote:Also inb4 venam closes this ;)
That's lame.
I don't get that line, what do you mean?


RE: The impracticality of c & projects - movq - 24-08-2015

(23-08-2015, 09:41 PM)Houseoftea Wrote: First: I've been Reading a lot and people keep saying c is impractical for modern projects. Useful only on embedded systems or for kernels. Is this because its a low level language or its lack of objects or are they wrong?

I know some Java and Python programmers who work on "modern" projects. Those people think on a completely different level. It's a bit hard to explain... They're more like "software architects" instead of "programmers". They don't build rooms nor houses, they build entire cities and countries. Some of them even try to build an entire planet. From their point of view, using C is like using scissors to cut a tree.

It's also important to note that those people are often professional programmers (as in: they get paid for writing code). With very tight schedules and huge piles of TODO lists, they simply can't afford taking the time to write good C code.

They are very pragmatic people. They want libraries and frameworks that do most of the job. Why? Because it's less time consuming, it's much easier and it's less error prone.

Thus, they rightfully argue that C is impractial -- at least for what they do.

At the other end of the spectrum, there's us. I guess that most of us "work" in our spare time. We're enthusiasts. It's not even "work", we're doing this for fun. There's no nagging customer. There's no manager. We care about clean code and simplicity. We care about the little details. And we're not forced to comply to weird specifications (most of the time).

For us, it's a lot easier to use C. It is indeed practical.

However, I don't know any professional C programmer in person. I'd be interested to know: How does the work of professional C programmers differ from the work of Java and Python programmers? What kind of software do they write? Why do they use C? Did they even choose C or is it a requirement?


RE: The impracticality of c & projects - z3bra - 24-08-2015

(24-08-2015, 01:37 PM)vain Wrote: However, I don't know any professional C programmer in person. I'd be interested to know: How does the work of professional C programmers differ from the work of Java and Python programmers? What kind of software do they write? Why do they use C? Did they even choose C or is it a requirement?

I know a few of these guys. They're especially knowledgeable and I consider them as "code gurus". One of them writes drivers for a living, so you might argue that he works with hardware and that's why he writes in C. But as a hobby, he also uses C for totally different projects, eg using ncurses. And you'd have a hard time finding flaws in his code, because C isn't a language anymore, but his preffered tool to be build, well... tools.

It's like when you build a house, you don't think about which hammer you should use for what. You just grab that good'ol hammer that's been with you for the last 10 years, and use it like an extension to your arm.

It's just a matter of habits. The language really doesn't matter in the end.

@venam: I read it like an implicit complaint that you close all threads, not sure why.


RE: The impracticality of c & projects - apk - 24-08-2015

(24-08-2015, 08:54 AM)venam Wrote:
(24-08-2015, 07:38 AM)z3bra Wrote: PS: as for the last line:
Quote:Also inb4 venam closes this ;)
That's lame.
I don't get that line, what do you mean?
There have been times in the past where you have closed Houseoftea's threads for breaking forum rules. I am sure he meant it sarcastically.


RE: The impracticality of c & projects - Houseoftea - 24-08-2015

Thanks for all the great responses!

I did mean it sarcastically by the way, sorry for any confusion


RE: The impracticality of c & projects - pranomostro - 31-08-2015

I am not sure about C.
I have done a lot of programming with it, and in the future it also seems like I will do more with it, but sometimes I bang my head on my table and against my wall because my malloc sets a struct and a string to the same memory position (I still remember it: 0x6010111) and I can't find out why and then I wish I had done it in lua.

I would say C is good if you want to write a small, self-contained command line-utility, like cat, or a programming language. These are tested often, speed is crucial, and it is _very_ portable.

Things I wouldn't use C for is developing something security critical. Seriously, we have to ban this. Heartbleed was one example, and there is so much more that we don't know-this should be stopped. seriously.


RE: The impracticality of c & projects - srp - 01-09-2015

(31-08-2015, 07:26 PM)pranomostro Wrote: Things I wouldn't use C for is developing something security critical. Seriously, we have to ban this. Heartbleed was one example, and there is so much more that we don't know-this should be stopped. seriously.

I don't see any specific programming language being beneficial in security applications. That's like me making a shitty PB&J and blaming the breadmakers for it.

Stuff like that is human error when they develop the application. Programming languages aren't made with security in mind (besides any runtime-based languages, such as Java and the HotSpot VM). Anyone can make an insecure program in any language.


RE: The impracticality of c & projects - pranomostro - 01-09-2015

(01-09-2015, 02:02 PM)vypr Wrote: Stuff like that is human error when they develop the application. Programming languages aren't made with security in mind (besides any runtime-based languages, such as Java and the HotSpot VM). Anyone can make an insecure program in any language.

That may be true, but C makes it easier to do these mistakes. It is easier to not null-terminate a string in C, in another language this has been done reliably by the person creating the language (most of the time). There is a single point of failure and not thousands of them like in C. And there are many more examples for this. I don't want to say that C is totally not suited for security stuff, but it is much easier to make critical mistakes (buffer overflows, not-terminated strings, gets() and much more) than in other memory-safe languages.


RE: The impracticality of c & projects - srp - 02-09-2015

(01-09-2015, 04:29 PM)pranomostro Wrote: but C makes it easier to do these mistakes

C wasn't made to prevent the programmer to do various things. That doesn't make C an insecure language, that means the programmer needs to pick up a book on making secure applications in C.


RE: The impracticality of c & projects - z3bra - 02-09-2015

(02-09-2015, 10:23 AM)vypr Wrote: the programmer needs to pick up a book on making secure applications in C.

This is not as simple as that. C is a language that doesn't even try to fix runtime errors.
Out-of-boundaries arrays, random memory reads, unterminated strings, ... Some languages actually provide checks for these, and thus prevent leaks and exploits based on this (remember heartbleed?).
Sure, this would have been prevented if the devs didn't make such an error in the first place. But hey, if people didn't make any error, we wouldn't even be discussing this.
Everyone makes errors, this was true in the past, this will be true in the future. And C will always let you make such errors, while other languages don't.
If you think your application is a bit "risky", and your codebase starts to be hard to review, then C might not be the best language.


RE: The impracticality of c & projects - pranomostro - 03-09-2015

>C wasn't made to prevent the programmer to do various things. That doesn't make C an insecure language, that means the
>programmer needs to pick up a book on making secure applications in C.
Don't get me wrong, I am a very strong advocate of C, and I am completely against banning it. But as z3bra already said,
even if you would want to make secure applications in C, it wouldn't be that easy. Preventing the programmer from doing things he does not want to do (overwriting protected memory) is actually a good thing imho.


RE: The impracticality of c & projects - Pr0Wolf29 - 10-09-2015

C is not impractical. I could do everything I do in C++ in C, but I figure most of C++ is just abstractions on top of C I'd have to write anyways. Performance losses are fairly negligible too.


RE: The impracticality of c & projects - ninjacharlie - 10-09-2015

Along with what everyone else has said about the unsafe aspects of C, I wanted to throw in my two cents.

First, the Xorg API is a mess. It's not fun to write and is poorly documented. I wouldn't recommend jumping right into that immediately.

Secondly, here's a list of a few interesting C projects I've come across while surfing GitHub daily for ~a year.

1) DOOM (https://github.com/id-Software/DOOM), the classic first person shooter. It's code is great and is completely written in C. It make take a little work to get it running, but just looking through the code is worthwhile.
2) Vis (https://github.com/martanne/vis) a vim clone. Associated with the suckless.org projects :)
3) Any suckless.org project
4) C4 (https://github.com/rswier/c4) a C compiler in 4 functions. It's a little dense, but it's a fascinating project.
5) Corange (https://github.com/orangeduck/Corange), a 3D game engine in C. Most 3D game engines are written in C++, and this is one of the few exceptions I've found. Check out SDL, if you want to write graphics stuff in 2D.

Bonus: Build Your Own Lisp (http://www.buildyourownlisp.com/), learn to write a simple Lisp compiler in C. Teaches some basic C concepts too, if you need a little extra practice with the foundational concepts.


RE: The impracticality of c & projects - apk - 10-09-2015

*COUGH* ADA *COUGH*


RE: The impracticality of c & projects - srp - 10-09-2015

(10-09-2015, 05:18 PM)dsplayer14 Wrote: *COUGH* ADA *COUGH*

have you even poked Ada with a stick?


RE: The impracticality of c & projects - apk - 11-09-2015

(10-09-2015, 08:10 PM)vypr Wrote: have you even poked Ada with a stick?
nah man she died in 1852


RE: The impracticality of c & projects - dtnt - 11-09-2015

Which would be the perfect opportunity since she can't defend herself anymore.


RE: The impracticality of c & projects - Houseoftea - 21-09-2015

Do you people think k&r is still valid for learning?


RE: The impracticality of c & projects - z3bra - 21-09-2015

yes. 5char


RE: The impracticality of c & projects - ninjacharlie - 21-09-2015

(21-09-2015, 08:59 AM)Houseoftea Wrote: Do you people think k&r is still valid for learning?

Most definitely. It's one of the more useful C books out there (even today).


RE: The impracticality of c & projects - cjm - 21-09-2015

(21-09-2015, 09:03 AM)z3bra Wrote: yes. 5char
That made me choke on my coffee. Good joke :)


RE: The impracticality of c & projects - pranomostro - 07-11-2018

Quote:I don't see any specific programming language being beneficial in security applications. That's like me making a shitty PB&J and blaming the breadmakers for it.

I don't see any knife being better at cutting bread, so I just use my katana.

I'd phrase it this way: Given a random programmer who knows C and, say, Python equally well, it will take the programmer less time to produce a program with the same amount of bugs and security flaws with Python than with C.

You _can_ cut your bread with a katana, but J. Random Hacker won't be able to without cutting a lot of non-bread first.


RE: The impracticality of c & projects - Dworin - 07-11-2018

Maybe it depends on what type of program you're writing. I'm teaching* numerical methods using the Chapra&Canale book. They give some very clear examples of structured pseudocode. To translatie that to an actual program needs just type definitions and interpunction. The difference between languages is surprisingly small.

*Not that I'm such an expert


RE: The impracticality of c & projects - pranomostro - 08-11-2018

@Dworin: I was writing about security applications. With other applications, I personally don't have any objections to using C. Heck, I myself use C all the time in programming situations where it is wholly inappropriate!