This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Can you write object oriented code in C?
Hi, can someone point me to a tutorial explain me how OOP concepts can be implemented in ANSI C:
virtual functions
inheritance
best practice
A book about OOP programming ANSI C would be great too.
Here is the link of a book on this topic: http://www.planetpdf.com/codecuts/pdfs/ooc.pdf (Object Oriented Programming in Ansi-C - exacty what you were looking for).
Good luck and have patience. Writing OOP in C is not an easy task, but can be somewhat rewarding if you like extreme things !
Another starting point will be to check GObject: http://library.gnome.org/devel/gobject/ and as #unwind said GTK is a good example of how to use OOP concepts in C. You can also take at GLib, is a nice library that will certainly make your C programming life a lot more easier, it is programmed in OOP manner, and as a plus is portable!
Objective-C isn't C - it's a different language.
C isn't an object-oriented language. It's possible to do some OO-style stuff, but it's not what it's built for.
Best practices in C are procedural.
I would recommend looking at the internals of the GTK+ GUI toolkit. It's an object-oriented system written in C, showing off the techniques you're after. It is open source, so there's nothing stopping you from reading it and learning.
Object-oriented mechanisms aren't defined as features of the C language. You'll have to emulate object-orientation by adding your own logic on top of the procedural nature of C.
I wouldn't recommend applying every aspect of OOP in C. While encapsulation is relatively easy to achieve, implementing inheritance would be really ugly in a language that wasn't made for that.
A good tutorial on that: http://www.planetpdf.com/codecuts/pdfs/ooc.pdf
Related
I'm looking for an Ada constructed framework for AI. I think Ada would be perfect for implementing temporal and stochastic paradigms due to its tasking and real-time mechanisms, but did not find anyone who tried to make such a libraries. Actually I did not find strong implementations on other languages too. For C# I found http://www.c-sharpcorner.com/1/56/, and for C++ I found http://mind.sourceforge.net/cpp.html but both did not get much popularity. Maybe java has good AI libraries too, but I do not know. So, do you know an Ada implementation? Would it be useful for more anyone? If you know libraries from other languages, it would be useful to know and compare the implementation models in java, for example. Thanks.
Here's a few resources:
Book, rather old, though (1989): Artificial Intelligence With Ada
Looks like some kind of university student dissertation: MUTANTS: A generic genetic algorithm toolkit for Ada 95
Dmitry Kazakov's AI stuff, mostly fuzzy logic. (Dmitry writes really nice software.)
I once had a school AI project that used the CLIPS AI builder library.
Since I avoid coding in C where I don't have to, I made an Ada Binding to it, which I believe is licensed without restriction. If you want it, have at.
I used it to build an expert system capable of playing a user's opening moves in Empire. All the code is either in Ada, or Clips' expert system specification language.
Here's a potentially useful Java library. I haven't heard of any Ada libraries. Ada is a great language, though.
Here's some genetic stuff.
I want to create an algorithm using genetic programming, based on symbolic regression.
I read some articles about that, some examples written on java or c++.
Maybe is more difficult because it isn't OOP, but is it possible to develop genetic programming in C?
What do you suggest to me to start programming? Any books/articles/examples to read?
I tried googling about that, but I didn't find anything interesting..
Thank you, cheers.
I've used GAUL in the past, and I'm fairly certain it's written to work with C. It did the job for me.
What do you suggest to me to start programming?
If you're starting to program I highly recommend a modern language that comes with a rich set of libraries and is more forgiving to beginner's mistakes.
Free environments are available for most languages, personally I'd suggest C# (using either the free MS stuff or Mono) or Java (using Eclipse).
Groovy or Python are good choices, too.
You most definitely won't start with C, that is assuming you're not constrained by some particular environment your solution has to run on that only supports C.
Just my 2c ;-)
Cheers,
Jay
It's definitely possible to implement genetic algorithm with C. If you just wanna focus on the algorithm experiments without the machine details and have not yet known C, then I recommend python.
TinyGP was originally written in C so yes, it is possible to implement genetic programming with C. For genetic programming I would recommend the Fiueld Guide to Genetic Programming since its freely available and has a lot of references. It is very practically-oriented but not as thorough as other texts.
I have been playing a MUD game now off and on for over a year. I have scoured the internet looking for the best computer language to learn to develop my own. So far, I have come up with nothing but C. Is C the best language to learn for this application, or is there something better?
I know SMAUG was written in C, but that was years ago. I am new to programming in general and have some experience with Python. I have been playing Aardwolf, which allows it users (after a certain level) to create their own area's. The user does this using Lua. This was interesting to me, because Lua is a "scripting" language. So this begs another question - Do you build the game's format in C (or something else) but create the world with a script?
Also, this would be a game with only my friends, so a direct connection would be required since I would not be hosting it online. So, once again, I would like to dive into this world and use this as a pet project to also help me learn a programming language... but which one would be the best that would also allow me to scale it uo in the funture
P.S. - Any open source code out there that I can look at and study?
So, once again, I would like to dive into this world and use this as a pet project to also help me learn a programming language... but which one would be the best that would also allow me to scale it uo in the future
Most MUD codebases tend to be in C, but this is mainly for historical reasons. MUDs were fairly popular a while back, and at the time, C was by far the best language for portability which was supported by most hosting options out there.
That being said, a MUD is really fairly simple, in many ways. You could easily write a MUD in any language, provided it supports sockets and text parsing. Using a language with a good string parsing and high level socket support would actually be far simpler than some of the classic MUD code bases.
There are a ton of available MUD engines available online : a quick look at MudConnector will give you a ton info of available servers, software and code bases.
As for your programming language of choice, if you intend on only making it available to you and your friends, Python would be fine - I made one entirely in Lua a few years ago and it was a breeze. It's a great learning experience !
perhaps you should look for a MUDOS
http://www.mudos.org/
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
I want to begin programming i have no previous programming experience so can is start programming with C ?..Some people told me to start with perl or python .. So can i start learnning it without learnning python or perl first ?..And if so is the "Programming in c" book by steve kochan good to start with ?..http://goo.gl/Jh6bE
I'd like to contradict all the other answers given by my fellows: before you go off using OOP stuff or higher level languages, you have to know what's going on under the hood of all the fancy garbage-collection-template-multiple-inheritance-whatever-voodoo or you will get into trouble sooner or later.
It is absolutely essential to know that every single memory allocation is expensive and that you have to take care of your memory, for example.
I started programming using C and find it quite easy to learn new languages with my C background. Programming isn't about creating fancy user interfaces by dragging-and-dropping controls from a toolbox: that is just the topping. But before applying topping, you need some cake to put it on. If you don't know how to bake the cake, you'll never create a fancy one.
C is a simple language where you learn how to code some loops, conditionals and so on. It has – aside from pointers and sick #defines – almost no weird language constructs. Once you know how to set up the basic stuff, it'll be easy for you to transfer that knowledge to any other language.
I think, learning C is the first step to become the Duct Tape Programmer. If you're not interested in that, then it would be perfect to start programming with BF, Whitespace, FALSE or any other language...
I would not recommend starting with C. C wasn't designed to be a teaching language, and some aspects of it aren't very intuitive. It introduces a lot of complexity up front, and you'll be spending more time asking why something isn't working the way you want it to than actually getting things done.
As introductory programming languages go, Python is much friendlier and easier to get started in.
Entire generations of programmers started with C, no reason you can't either.
Python is an overall easier language to learn however than is C, so you might be able to learn the basic principles more quickly than you would starting with C.
As to the book you mention, I've never read it so can't comment on it.
I would recommend learning to program in a higher-level intepreted language such as Perl, PHP, Python... if you then want to go lower-level and learn C, you'll have a good basis, and won't have been "thrown in the deep end" so much. You'll also likely find more junior development positions for those languages, if you're looking to start a career.
Having said that, knowing some C can be helpful to give you an understanding of what's going on "under the hood".
You can start programming with C, although C isn't perhaps the best choice for learning. I personally recommend Python since it was designed in part for novices. Perl is probably a bad choice for novices given its interesting syntax. If you need to get close to the machine, or you're going to programming in micro controller space then you will likely need to learn C, but its probably not a good first choice.
I can't comment on Programming in C, but I can recommend The C Programming Language if you're a motivated self learner.
You could do, but I really wouldn't recommend it. Most active software development occurs in vastly, vastly different languages like C++, Java and C#. You'd be learning a language whose heyday is many years past, and whose best practices are decades out of date.
You can start programming in C. However, if you've never programmed before, it's almost certainly going to be much easier to learn a higher-level language to begin with. And unless your interest in programming lies in a few narrow areas like operating systems, it's unlikely you'll want to use C in the future.
The answer is of course "Yes", but C may not be the best choice as a first language.
You've to master some fairly advanced concepts before you can do the most basic things.
There are other laguages that are much friendlier such as C# and Java. If you know folks with Perl and/or Python experience that will help you, then go with either of those (I'd pick Python as a first language, if I had to choose between Perl, Python or C.
Personally, if I had to help someone get started with Programming I'd get them started with C#, but that's because I work with it everyday, and you can make it as simple or as complex as you like.
Short answer: yes.
Since you have no previous experience, when you learn your first language you are learning two things actually:
1) The syntax of the language, where it wants its commas, curly braces, and stuff like that
2) General programming principles
The reason people tell you to try something simpler, like Python (or PHP would be my suggestion) is that some languages make you type in a lot of stuff that has nothing to do with the problem at hand or what you are trying to learn. In other words, you spend too much time with some languages learning things that are specific to that language, making it hard to learn general programming.
Anyway, my suggestion would be PHP because they have great tutorials, you can get some programs going that do things, and learn the basics fast.
Also remember: all committed programmers know multiple languages and learn new languages fairly regularly, so the first one you pick will not determine your destiny. Pick the one that is appealing to you for your own reasons.
...and enjoy! Welcome to programming!
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
since I was at the first year of my University I always envied my fellows (mainly coming from a tech-oriented professional school) for knowing C. I came from a natural-sciences-oriented lyceum and never had programming experience or courses but some summer work with PHP learned from a teach-yourself-PHP-in-7-hours (and my programming interest was very recent). I want to know ... was it a legitimate envy? Does any programmer have to know C? Does C provide deep understanding on how a system works or how programming has to be carried out? I know that when programming C you have to have a strong understanding about buffers, memory, and so on. So I want your opinion on it.
No, you don't have to know C. But knowledge of C (or any other "close to the machine but not assembler" language) greatly enhances your potential as a programmer. Because you will understand a lot more of the inner workings.
And of course knowledge of assembler is also valuable. But in the above paragraph, I wanted to target the low end of computer language. Just because in modern languages, we take so much for granted (OO, extensive libraries, garbage collection to name a few). And yes it helps us programmers to work more efficiently. But it hides some of the machine aspects that we sometimes need to see and that's why it is so important that we need to know the inner workings.
While I think it is important to understand memory allocation, pointers, registers, ... I would say that too much experience in C can also be a barrier to grasp higher level languages, or OO languages. C tends to make you think procedurally and that can be a bad thing in some cases ...
I would definitely not recommend C as a first language, but it can be of great help to do some C at some point...
As a side note, I think that assembly can be much more useful to help you understand basic principle. At the same time assembly is far enough from any language that you would use (unless you work in a very specialized field). That will help you keep a different mindset when doing assembly than when using a higher level language.
This is a quite discussable topic. I personally think that knowing C enhances your ability to work with other languages too when you understand what's going on under the hood. But you don't have to know C to be able to produce high quality code.
Eric Sink has also once thought of that question.
Something I find missing from most of these answers is that C is a very easy language to learn. Everything you'll ever need to know about the syntax is contained in one thin, concise book (K&R), and that includes all the standard libraries. So I'd encourage you to at least skim a book and see what it's all about, even if you don't intend to use it.
That simple C syntax only gets expanded for most modern C-based languages (C++, C#, Java). You can't say you really know those languages until you've mastered at least a subset of the hundreds of libraries that come with them, and that can take months or years of experience.
What's tough about C is that it can expose you to the true nature of the machine underneath. If you really want to grok how a computer works, you need to understand things like pointers, memory allocation, and stack vs. heap vs. executable code. You can learn basic C syntax in a few hours, and that puts you on the road to understanding much more. Saying "I'm a C expert" is just a proxy for saying, "I really understand how a computer works."
You don't necessarily have to know C, but imo every programmer should know about basic machine architecture and how applications interact with the OS and the hardware.
Obviously if you're going to study this, C is a good choice for a language, but not the only option.
Another good reason to know C is that a lot of code is written in C so if you want to learn from others code, it will be very helpful.
In addition to Gamecats answer, in my experience working with people in other languages, there is a difference in skill between the guys that know C and the guys that don't. I work primarily in Java and certainly appreciate having spent a few years working with C before I did. On top of that I also did quite a bit of Perl work as well. I would say knowing as many languages as possible helps to give you different views on your work and applying different paradigms
C is not my language of choice, but even to this day, C is everywhere.
When I do some small code in Lua using LuaCurl, I use a C library. Lua itself is written in C.
When I do some Seaside Web application in Squeak Smalltalk, I use a VM generated in C (the Squeak VM is written in Smalltalk, and then it generates C code as a portable assembler).
So I would not start learning programming with C (see this thread for other choices), but as a programmer, knowing C is very handy even if it is not your language of choice.
In the same way that not every mechanic needs to know the inner workings of an engine to fix a car, not every programmer needs to learn C to produce code.
however, the ones who do, acquire a better understanding of the craft and ultimately achieve a higher level of success.
I share the same sentiments as the others in this thread, however, to answer the question that was asked:
The only programmers that have to know C are C programmers.
All knowledge is useful, so yes, you should envy their knowledge. You should also envy people who are AI nerds and know LISP, etc. The best mix would be a dynamic language, a functional language, SQL, a low level language and an object oriented language.
If you want some stranger to make some recommendations, I would go Python, OCaml, SQL, C and Java/C#. But, find your own path :-)
I think you have.
Languages have their own evolution. They developed within a very intriguing and fast evolution of computer systems. CPU power grew, features grew, Assembler got more complex... everything got more powerful.
Thing is: if you never saw the low level and "easy" beginnings, and you start with some high-level languages like C#, C++, or Java, you won't understand the elegance or backend perspective of these very powerful languages.
I think you don't need to learn LISP, because if differs a lot from common C-like languages. But some C is a must-know. It's for developers from developers, very near to machine code. Know what the machine does when you program it.
Memory allocation and pointers.
After getting to handle C and C++, even if only in school, you have a better understanding of what needs to happen in memory in order for you to throw objects and references around and you get a better appreciation of what, for instance, garbage collection implies.
Also, in school, starting with Pascal and then C allowed us to learn "programming" first, the old way, and then move to more advanced languages (OOP, etc) on top of that.
Have to know/learn C? Probably not, although it might make learning some concepts easier. Understanding something about memory allocation, structures and pointers of all kinds is worthwhile and C is a good language to use to gain that understanding. Plus, to be honest, "straight" C is really not complex. Tricky to get right, sure, but not in itself complex. I'd advise getting hold of a compiler that wasn't a C++ one too, that way can lie madness. (Fond memories of Quick C For Windows)
Have to know/learn C++? Definitely not.
I would use a metaphor: Knowing C for programmers is like knowing latin for (western languages) writers. It is not something you need, especially if you just write sports columns or cooking recipe books, but if you want to refine your craft it is something that I would consider nearly mandatory. But it will not be useful for daily work on ordinary software.
Or knowing mechanics for a car pilot, or how to build sails for a sailor. At some level of expertise, you need to know how the things you use are working internally.
If you learn C, try to master the pointer concept, and the way they map to the hardware. That's really the point of learning C. Do not spend time on the rest of the language.
Maybe it was just my particular educational experience, but I hated C/C++ in college and haven't touched it since. I'm thankful for learning about the concepts involved, like pointers and memory allocation, but trying to accomplish anything with the tools that were available to me was too cumbersome for me to want to bother. I hope your experience is better.
("slightly" tongue-in-check) You should learn it if, for no other reason, than it will make you love whatever language you're working in at that moment.
I don't call myself a C programmer, but I can write code in C. It has helped me a number of times in my career. I've spent a lot of time working with Visual Basic, and there are some things you just can't do with VB. It's been very handy to drop down to C to do things like windows hooks. It's made me the "hero" a time or two.