How do you think in C/C++?

aimless

Junior Member
Jun 21, 2001
9
0
0
Hi, I'd like to learn C/C++ eventually but am sort fo hesitant to. Basically, what's the mindset you have when writing programs? What are you thinking, what do you plan to do, how does your mind work? It's a lot easier to imagine HTML, having a defined structure of opening and closing. From what I've seen of C I don't know where to mentally "think" of a starting or ending point, what to do next, where to go, how to do it, etc. What's the general attitude you have when programming C/C++?
 

Elledan

Banned
Jul 24, 2000
8,880
0
0
Divide the task (program) in sections, code all sections and make sure they work when put together.
 

hans007

Lifer
Feb 1, 2000
20,212
18
81
you think like lets say you were gonna build a car. from scratch. so you think about how to do every small part first and make it into one big part. think simple. simple is the best, you have the most efficient easy to read programs.

i guess in a word, hierarchal.
 

Killbat

Diamond Member
Jan 9, 2000
6,641
1
0
So, you're what, asking for a written style of thinking to absorb? Just start doing it, your brain will figure it out.
 

littleprince

Golden Member
Jan 4, 2001
1,339
1
81
noe wut you wanna do before you start typing...
plan something out in your head...

your gonna want a motor to provide momentum
a chair to sit
wheels to turn etc...

than start working on each part...
 

gittyup

Diamond Member
Nov 7, 2000
5,036
0
0
Here is a good simple example.

You need to write a checking account program for a bank in C++.

First, you need a class to represent the checking account.
public class checkAccout

Second, think about what makes up a checking account. Create members for class checkAccount.
private int acctNumber
private int balance

Third, you need to handle transactions on that checking account. Create Methods for class checkAccount.
public assignAcctNumber()
public depositFunds()
public withdrawFunds ()
public getAcctNumber()
public getAcctBalance ()
etc.....

 

Cattlegod

Diamond Member
May 22, 2001
8,687
1
0
its easy enough to learn by yoruself. however, if you wnat to learn object oriented programming, i suggest taking a course at a local college or something. that technique is hard to learn by yourself.
 

After being emerged in OOP for the past six years I have to tell you it rocks going back to straight C. All that OOP stuff is really good for business programming and light systems programming (if the OOP is kept in check). After you pass a certain point with OOP, the law of diminishing returns kicks in and it becomes pretty counter-productive.

I am doing C and simple C++ (just objects, no hardcore OOP stuff) now on a side project and I love it.

Where the hell is my copy of MASM!!!
 

slipperyslope

Banned
Oct 10, 1999
1,622
0
0
Well programming in C and C++ can be two totally different mindsets. C is a Functional language while C++ is Object-Oriented. You can compile C code in C++ code but the mindsets are two different things. Each is a great language but are good at different things. If I were you, I would learn C first. You will learn a lot of lower level stuff and after you have mastered that you will think that C++ makes all the tedious crap really easy.

Another good language to start with IMO is Java. If you do start with Java then it makes learning C more difficult but with Java you don't have to learn as much off the start to do some cool programs.

Private message me if you need any other advice.

Jim
 

StageLeft

No Lifer
Sep 29, 2000
70,150
5
0
Generally I get piss drunk and then just open up notepad and go mad! I go hog wild. THen when I'm sober I spent the next 5 weeks debugging the mess I made.
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0


<< i see a bunch of 1's and 0's when i code. >>



I'm sorry.

Personally, I try to think in an abstraction of the implementation language. I don't &quot;think in C&quot;, I think in the problem domain, and that can be applied to any implementation language (that I know). My higher-level thought thinks &quot;allocate memory&quot;, and my lower-level thought thinks, &quot;if ((s = malloc(n)) == NULL) // doh&quot;



<< Where the hell is my copy of MASM!!! >>



Preach on brutha! MASM is linked here

I've gone back to doing a lot of my win32 stuff (personal) in masm, simply because I find it to be more fun.



 

Descartes: Awesome link, thanks. I think I will start doing my business programming in ASM see how long it takes for me to get fired :)

Some people here have a hard enough time understanding simple Java. I would love to see the look on their faces if I replaced their Enterprise Java Beans code with 2,000 lines of ASM.
 

hans007

Lifer
Feb 1, 2000
20,212
18
81
i knoe c and c++ and i'd have to say i'd like c++ because you can do everything in it that you can do in c and more. i had to take a network programming class and tried to do it in c++, but the compilers on our sun servers were not configured right for c++ but i had to do it in c. c gives me little hassles like having to declare vars at the top and other stuff. then again i learned c++ first.
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0


<< c gives me little hassles like having to declare vars at the top and other stuff >>



Nonsense my brutha! :)

void foo()
{
int you_can;
{
int declare_variables;
{
int at_the;
{
int top_of;
{
int any_scope;
}
}
}
}
}

Of course, that's an extreme example, but you get the idea. Sorry, the formatting will be lost once I post this.
 

cmv

Diamond Member
Oct 10, 1999
3,490
0
76
If you don't know how to organize it just sketch out a beginning and put it together quickly with shoddy code. So shoddy that you can't possibly think of releasing it or using it in production. I do this sometimes by just doing mini projects. Once you have something working how you want it to function rewrite it to be integrated into your program (don't just edit, start over but keep what you learned from the test implmentation in mind). The most important thing is to start somewhere... Don't let the overwhelming idea of a completed program stop you from beginning something... If need be start extremely simple and work your way up.

Just be careful never to use testing code in an actual production. If you do it will eventually bite you in the ass because it will be impossible to maintain. By shoddy code I mean doing things like leaving out comments, not testing return values from external functions, etc... Only useful for small projects, not large ones :).
 

arcain

Senior member
Oct 9, 1999
932
0
0
Just to be an ass, C is actually an imperative language. Scheme and Lisp are functional languages.
 

Ameesh

Lifer
Apr 3, 2001
23,686
0
0


<< Just to be an ass, C is actually an imperative language. Scheme and Lisp are functional languages. >>



very true!


i like flow charts too, they work well in C stuff, C++ requires a little more detailed flowcharts.