Why C++ …

Moderator
Posts: 1,140
Joined: 2005.07
Post: #16
I'm not saying it's the be all and end all, I'm just saying it seems to fit my coding style very well. Right now I'm kind of curious to see what these "power tools" are.
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #17
Well, here's something cool:
Code:
(define (square x) (* x x))

(define (tree-map func tree)
  (make-tree (func (datum tree)) (map (lambda (x) (tree-map func x)) (children tree))))
If you then call (tree-map square tree) it will return a copy of tree with all the data in the tree squared.

You'll notice that functions are just data, so you can pass them around without any messy function pointers.

The way this tree structure is laid out is with three functions: (make-tree datum children) which takes a datum, and a list of child trees. (datum tree) returns the datum, and (children tree) returns the list of children.

Map is a function that takes a function and a list, and returns a list whose elements are that function applied to each element of the list.

Also, function calls always precede the arguments (even for arithmetic) so (* x x) is like x * x in C.

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #18
That's kind of cool. So it's basically a simpler/quicker way to do function pointers? It does seem to broach on the issue of readability, though.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #19
I thought functional code was really hard to read too before I took a programming languages class. Probably one of the best classes I've taken. Now I still think it's fairly hard to read, but definitely allows some very elegant and simple solutions to a lot of problems.

I also liked OCaml better than Scheme as far as functional languages go. Scheme has a very simple straightforward syntax, but is fairly hard to read. OCaml has a much more natural syntax. (Without millions of ()'s) Of course, Scheme's syntax allows code to be manipulated as a tree, OCaml cannot do this as far as I know.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
DoG
Moderator
Posts: 869
Joined: 2003.01
Post: #20
akb825 Wrote:I'm not saying it's the be all and end all, I'm just saying it seems to fit my coding style very well...

Does C/C++ fit your coding style, or does your coding style fit C/C++? Wink
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #21
The readability isn't so bad if you have both proper indentation/linebreaks and proper syntax coloring, neither of which are possible here Smile

And yes it's kinda like function pointers, except it's more flexible - no types, no pointers, and you don't have to give everything a name. You could just as easily pass (lambda (x) (* x x)) instead of the square procedure and it would be just as happy.

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #22
DoG Wrote:Does C/C++ fit your coding style, or does your coding style fit C/C++? Wink
Well, I learned first in Java (for school), but as soon as I taught myself C/C++ shortly after, I have been using it exclusively for my own projects. Since it was pretty much part of my learning process, I'm sure it helped shape my coding style. But I'll put it this way: whenever I'm using C/C++, I never feel "trapped" or that there's something that I need that's missing. I suppose that could partially be because I haven't experienced some of the features of other languages. However, from what I've seen here, I haven't seen anything that I really want to use.
Quote this message in a reply
Moderator
Posts: 608
Joined: 2002.04
Post: #23
akb825 Wrote:Well, I learned first in Java (for school), but as soon as I taught myself C/C++ shortly after, I have been using it exclusively for my own projects. Since it was pretty much part of my learning process, I'm sure it helped shape my coding style. But I'll put it this way: whenever I'm using C/C++, I never feel "trapped" or that there's something that I need that's missing. I suppose that could partially be because I haven't experienced some of the features of other languages. However, from what I've seen here, I haven't seen anything that I really want to use.
Ruby has spoiled me.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #24
Josh Wrote:Ruby has spoiled me.

Yeah, I think Ruby is the only language I use where I don't constantly go "well, if I had *that* language feature, this would be easy..."
Quote this message in a reply
Member
Posts: 749
Joined: 2003.01
Post: #25
After using cocoa a bit I kind of "got" the idea behind objective-c and am quite impressed (you kind of do everything by overriding existing methods Blink ). Indeed it allows for quick and clean use of the huge API.

But for a game, hmmm, I dont think you need as much "generality"... a "bare bones" object oriented framework is fine, such as Blitzmax's or the more simple C++ stuff.

Since you are not using "ultra general" code provided by others but your own, likely much more "to the point".

©h€ck øut µy stuƒƒ åt ragdollsoft.com
New game in development Rubber Ninjas - Mac Games Downloads
Quote this message in a reply
DoG
Moderator
Posts: 869
Joined: 2003.01
Post: #26
Najdorf Wrote:After using cocoa a bit I kind of "got" the idea behind objective-c and am quite impressed (you kind of do everything by overriding existing methods Blink ). Indeed it allows for quick and clean use of the huge API.

But for a game, hmmm, I dont think you need as much "generality"... a "bare bones" object oriented framework is fine, such as Blitzmax's or the more simple C++ stuff.

Since you are not using "ultra general" code provided by others but your own, likely much more "to the point".

"What's with all the "quotes"?" Rasp

Anyway, if you have a more powerful language to your disposal, you can write very general code that works very quickly, but still have the choice to speed things up by creating specialized code, or even dropping to C, most of the time.

For projects consisting roughly of more than a few thousand lines of code, probably even smaller ones, the overall complexity of a program written with high level scripting + C/C++ will worst case rival that of a pure C/C++ program with the same task.

The only potential downside of using a scripting language is performance, and that can be helped.

Also, working with a language that is less restrictive allows encourages to explore new ways of doing things, imho.
Quote this message in a reply
Member
Posts: 208
Joined: 2005.04
Post: #27
One language I really liked from my programming languages course was Gopher, a simplified version of Haskell which has since been supplanted by HUGS. I liked Haskell's syntax more than LISP's, primarily for its brevity. Here's some further reading if you're interested.
Quote this message in a reply
Apprentice
Posts: 17
Joined: 2006.02
Post: #28
akb825 Wrote:[...] whenever I'm using C/C++, I never feel "trapped" or that there's something that I need that's missing. I suppose that could partially be because I haven't experienced some of the features of other languages. However, from what I've seen here, I haven't seen anything that I really want to use.

Ed (a.k.a. fax) linked me to an article recently which covers that point very well. You can find it here:
http://weblog.raganwald.com/2006/10/are-...mmers.html

I'm sure you could talk to any programmer who has used something more high-level than C++ and you'd get the same response. When C++ was all they knew, it felt perfectly natural. Not so now that they've used lisp or python or any other language which ranks more highly on the blub scale.

And like Keith says, if you haven't used any of those languages, you owe yourself an education :-p

C++ still has it's place, of course. It's just not a good tool for every job - indeed, I'd say it's a bad tool for most jobs. Knowing the alternatives will make your life vastly less stressful when you encounter a job which C++ doesn't solve easily.
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #29
I'm in the last week of my programming languages class. We've gone through OCaml, Python, and we just finished Prolog. Of all of those, I think Python was my favorite, excluding some superficial problems. (namely using whitespace to determine scope and implicit variable declaration) However, while trying to keep an open mind, I still prefer to code in C++, due to keeping enough low-level control to try and make sure that I do things as efficiently as possible along with still keeping at least some high-level concepts intact. Sure, there's some corner cases that can sometimes cause some problems and/or ugliness with things such as templates, but there's also plenty of headaches that can be caused due to Python's dynamic types or with any other language. Bottom line is, I think C++ still fits what I do the best.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #30
You'll know you've become a good programmer when you change your mind ^_^
Quote this message in a reply
Post Reply