How do you actually DO anything?

T

Thomas J. Gritzan

peter said:
You might not need those in the beginning. I recommend that you learn C
++ by reading Koenigs book on C++ programming. I don't remember the
title and have only skimmed it, but it looked very good and has been
recommended from many sides.

Do you meen this one?
Accelerated C++ by Andrew Koenig, Barbara E. Moo
 
P

peter koch

Do you meen this one?
Accelerated C++ by Andrew Koenig, Barbara E. Moo

Exactly. Thank you Thomas - and to bad I forgot Barbara Moo who had a
very important role in the development of C++.

/Peter
 
S

Stefan Ram

In fact to implement malloc() or new requires something other
than full C or C++ (eg. a subset of one or other of them).

You might think of a »freestanding implementation«,
which is not a subset, but one of two kinds of »full« C++
implementations allowed by ISO/IEC 14882:2003(E) 1.4p7.
are there many people who learn to program without becoming
programmers?

Where I live, many students of other fields than computer
science have one or two programming classes (in high schools,
universities of applied science, and college). And often they
are taught C++ there, which seems rather inappropriate and
unfortunate to me, because C++ is optimized for run-time
efficiency for the cost of much more effort of the programmer
and carries with it all the C legacy. There are many
languages, where beginners can get more things done.

I wrote about this topic in

http://www.purl.org/stefan_ram/pub/c++_lernsprache_de

. This is a German-language page, but it has some English-
language comments and quotations at its ende.
 
M

Michael Mol

are there many people who learn to program without becoming
programmers?

If by "learn to program" you mean "able to instruct a computer to do a
few simple tasks programmatically", and by "become a programmer" you
mean "become proficient at programming", then, yes, there are many
people who learn to program without becoming programmers.

I spent five years tutoring computer courses at the community college
level, including BASIC, Java, C++, PHP and VB.Net. I've seen many
students learn to get programs as complicated as a bank account
simulator (A simple program that uses a class with a balance property,
a getter for said property, and methods for increasing and decreasing
said property), but not really have a clue (or care) what they were
doing, how they were doing it, or what they could do with it. Most of
them were only taking a programming class because they were trying to
get a degree in business management, and the curriculum required them
to take a programming course.

Is this typical at four-year and higher learning institutions? I
don't know. Is it typical for self-learners on the Internet? Again,
I don't know. But, yes, there are many people who learn how to make a
syntactically valid and functional program in C++ without becoming
what I would call a programmer. (And my definition is lax; If you
actually care about what you're doing, you'll eventually become
proficient.)
 
S

sean_in_raleigh

Right now, I want to make a program that changes the desktop
background at certain intervals.

Here's a simple program that does just that, for
your erudition:

#include <vector>
#include <string>
#include <iostream>
#include <algorithm>

#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>

using namespace boost;
using namespace boost::filesystem;
using namespace std;

bool
is_image_file(const directory_iterator &item)
{
// if it's a directory or any other non-file thing, say "no"
if (!is_regular(item->status()))
return false;

// if it doesn't end with image-file extensions, say "no"
if (!(ends_with(item->path().string(), ".gif")
|| ends_with(item->path().string(), ".jpg")))
return false;

// we got here, so say "yes"
return true;
}

string
get_random_image(const string& dir)
{
// we keep a list of image files we find in here
vector<string> images_list;

// this represents the end of the directory listing
directory_iterator end_itr;

// for each file in the directory ...
for ( directory_iterator dir_itr( dir ); dir_itr != end_itr;
dir_itr++)
{
// if it looks like an image file ...
if (is_image_file(dir_itr))
{
// add it to our list
images_list.push_back(dir_itr->path().string());
}
}

// if we didn't find any image files, just bail out
if (images_list.size() == 0)
throw "you need to put some images in here";

// shuffle the list of images so we can choose a random one
random_shuffle(images_list.begin(), images_list.end());

// choose the first image in the now-randomized list
string random_image = images_list[0];

// and send it back to the caller
return random_image;
}

void
set_desktop_background(const string& file_name)
{
// This command will depend on your operating system
string set_command = "gconftool-2 --set /desktop/gnome/background/
picture_filename --type string ";

// here we put the command together with the image file name
string full_command = set_command + file_name;

// and run the command
system(full_command.c_str());
}

int
main(int argc, char **argv)
{
// the program starts here

// this makes it so random_shuffle() will do what you think it
does
srand(unsigned(time(NULL)));

// forever ...
while (true)
{
// get a random image from the current directory
string current_dir = initial_path().string();
string image_file_name = get_random_image(current_dir);

// and set the desktop to that image
set_desktop_background(image_file_name);

// then wait 5 minutes until we do it again
sleep(60 * 5);
}
}

Sean
 
D

Default User

Preston said:
On 2009-03-23 17:39:45 -0600, "Default User"
<[email protected]> said:
PHP (and C#) programmers get used to writing in a typeless, C-like
syntax without worrying about pointers and memory, and it really
seems to throw them for a loop when they have to deal with it.

Well, we obviously have different views of this. I don't see much point
in going around and around with it. My experience has been different.
Naturally, there will always be people who have trouble transitioning
from one language to another.




Brian
 
M

Michael Mol

It's an enormous and overwhelming leap for someone learning to program
for the first time.  Dumping them into the Win32 or Cocoa/Carbon
environment when they're still figuring out how to do something in C++
at the command prompt?  Bad idea.

Command prompt and GUI coding are two extraordinarily different
animals. In command prompt coding, you may or may not need an input
loop, depending on your application. In GUI programming, you will
need an input loop, but it's more often than not abstracted away by
the language or a widespread framework, turning it into event-driven
programming, which makes writing program with simple requirements even
simpler.

In his specific case, he wants to periodically change the desktop
background image. That's hardly even GUI programming; You can
accomplish it with the OS's task scheduler, some disk access, a
shuffling algorithm and a write to the configuration registry. It
*may* be necessary to tell the window manager to refresh its desktop
image.

From there, he can apply iterative development to learn how to add the
features he wants to add. Over time, he'll accumulate a working set
of knowledge. At some point, he'll discover that he knows just about
everything he needs to know to accomplish something unrelated to his
original project that he'd assumed was too hard or otherwise outside
his reach.
 
N

Noah Roberts

I'm learning to program (C++ as my first language - a person
recommended it, saying I would understand OOP better).

I am not yet onto the actual OO things yet, but I understand
(basically) variables, arrays, pointers, and all the statements and
loops.

And yet it seems like I cannot do anything with my knowledge. The most
complex program I've managed to write is a program that squares a
number, returns an error if the answer to continuation questions is
not y/n, etc.

Would someone give me some code that shows me how to MAKE anything? I
can find examples, but I would not know what is GOOD code and would
inherit bad habits easily.

We've all been there. Just keep truckin'. Check out the various
websites dedicated to programming problems and solve the ones that
interest you.
 
M

Michael Mol

I'm aware of the difference.  I was responding to your statement that
"knowledge of the OS API isn't that big of a leap."  I disagree when
someone is still learning the basics of a language like C++.




If he is in fact using a UNIX-based desktop environment, this is true.  

I was thinking in terms of my experience in Win32, but I expected the
same to be true on Linux. I wrote a shell and perl script of an
analogous problem as my morning alarm clock.
Even so, messing with task schedulers, disk access, and configuration
registries is a lot for somebody who is just learning to program and
doesn't even understand arrays and pointers yet.  Save the APIs for
later, I say.

On linux, the task scheduler is as simple as crontab -e. On Windows,
it's a bit trickier to find, but it's still a manual setup once you
find the dialog. Disk access is fairly trivial on either platform. I
know roughly where the relevant registry entries on on Windows, but
I'd have to dig into the specific desktop environment on Linux, or
hope nothing is expecting control the X root window.

But I've offered to walk him through the process, so I can help him in
the tricky areas.
I still believe he should stick to terminal output until he has learned
the fundamentals, but hey, we all learn differently.  Just don't mess
something up!

Indeed!
 
J

Jorgen Grahn

Jorgen Grahn said:
[Java] has a garbage collector that makes memory
management easier.
And resource management harder. Some people want GC, but many (most)
do not miss it in everyday C++ programming.

I do not see how the memory manager makes the management
of other resources harder.

Me neither. You are right.
Java does not have language constructs for scope guards
(RAII), but this does not seem to be caused by the existence
of a memory manager. One can imagine a language with both a
memory manager and objects on the stack that are being
destructed when the scope is being exited.

But maybe the hype around the Java GC made it harder to see the
benefits of RAII. RAII certainly makes the benefits of a GC harder to
see.

/Jorgen
 
J

Jorgen Grahn

The problem with pointers is that books and websites dump a bunch of
explanations and diagrams on people without telling them what the
things are for. Fundamentally, they're most often used as a way to
reference something in memory from anywhere in your program.

Say you're making a game using SDL, and you want to load an image.
First you'd create a pointer to an SDL_Surface:

[snip example]

It's not the kind of explanation that I prefer, but I guess people
think differently about pointers. It is a bit too C-centric for my
taste, too.

....
You can use malloc() and free() in C++, but C++ has its own way of
allocating and freeing memory--new and delete. You should use new and
delete because they will automatically trigger a C++ class's
constructor and destructor functions.

I would rather phrase that as "new and delete create and destroy
objects". The "allocating memory" aspect of it isn't all that
important, and should not be stressed too much.

/Jorgen
 
T

Tony

are there many people who learn to program without becoming
programmers?

"If by "learn to program" you mean "able to instruct a computer to do a
few simple tasks programmatically", and by "become a programmer" you
mean "become proficient at programming", then, yes, there are many
people who learn to program without becoming programmers."

"Proficient in programming", is a future criteria, not a current one for the
concepts of programming are still in their infancy. There is no
"programming". Unless one is trying to play Wall Street and tout a
"consultancy" "built upon" "programmers".

"I spent five years tutoring computer courses at the community college
level, including BASIC, Java, C++, PHP and VB.Net."

So you were a teacher of the interim stuff and now feel as empty as those
that learned those useless things and wasted their time with?

" I've seen many
students learn to get programs as complicated as a bank account
simulator (A simple program that uses a class with a balance property,
a getter for said property, and methods for increasing and decreasing
said property),"

You sound like a detail person (specialist) rather than a first-rung
community college "teacher".

"but not really have a clue (or care) what they were
doing, how they were doing it, or what they could do with it."

Apparently they were teaching you but you didn't hear or you were not the
one for them to teach (the latter for sure).

" Most of
them were only taking a programming class because they were trying to
get a degree in business management, and the curriculum required them
to take a programming course."

"College as a milker of money comes to mind". But moreso: if you need to go
to college to get into business, you shouldn't be in business? Are destined
to fail? Ah, just don't know yet (hopefully)!

"Is this typical at four-year and higher learning institutions?"

Is what typical? "Idiotic" ("benefit of the doubt") homoginization of
everything in the name of <blank>?

"I don't know."

I believe you (that you don't).

"Is it typical for self-learners on the Internet?"

Are you suggesting that there are self-learners and
self-learners-on-the-internet?

"Again, I don't know. "

I believe you (that you don't know).

"But, yes, there are many people who learn how to make a
syntactically valid and functional program in C++ without becoming
what I would call a programmer. "

Me! :) ;)

" (And my definition is lax; If you
actually care about what you're doing, you'll eventually become
proficient.)"

Prescribed slavery withstanding.

Tony
 
T

Tony

I V said:
Jorgen Grahn said:
[Java] has a garbage collector that makes memory management easier.
And resource management harder. Some people want GC, but many (most) do
not miss it in everyday C++ programming.

I do not see how the memory manager makes the management of other
resources harder.

Java does not have language constructs for scope guards (RAII), but
this does not seem to be caused by the existence of a memory manager.
One can imagine a language with both a memory manager and objects on
the stack that are being destructed when the scope is being exited.

I believe C++/CLI is just such a language:

I dismissed C# as "MS Java" and CLI just an interface to "MS Java".
And other languages have explicit scoping constructs that allow for a
limited form of RAII, e.g. (Python):

Do you know what RAII is? What is it?

Tony
 
T

Tony

peter koch said:
Exactly. Thank you Thomas - and to bad I forgot Barbara Moo who had a
very important role in the development of C++.

I am very frugal (too frugal, but my time ya know...) when actually buying
books. I "read" "all" of the books, but buy very few. By "read", I mean I
can skim a tech book at the bookstore in a few mins and get the value of it
(meaning it doesn't justify being bought by me). That said, I bought
"Accelerated C++". Brand new even. (Probably before there was such a thing
as used books on Amazon). It's a good book. _I_ don't think it is
C++-specific (I didn't use the information within the context of C++). And
that's a good thing, IMO! In short, I learned from that book. Not to overly
elevate the book though: It's a specialize area of knowledge, but
foundations are important and "Accelerated C++" exposes and illuminates a
small void. Highly recommended to the student of programming*.

Tony

P.S. C++ is a relic in the evolution of programming languages, in 2009. It
was hindered by: 1.) Corporate slavery 2.) Comnittee "standardization"
 
T

Tony

Preston said:
It's an enormous and overwhelming leap for someone learning to program for
the first time. Dumping them into the Win32 or Cocoa/Carbon environment
when they're still figuring out how to do something in C++ at the command
prompt? Bad idea.

C++ and the Win32 API are on the same level. One is UNIX. One is Windows. :p

Tony
 
T

Tony

It's an enormous and overwhelming leap for someone learning to program
for the first time. Dumping them into the Win32 or Cocoa/Carbon
environment when they're still figuring out how to do something in C++
at the command prompt? Bad idea.

'Command prompt and GUI coding are two extraordinarily different
animals."

Not entirely: what is the application? User interface programming is UI
programming. The key is to separate the "meat" of the application program
from that. These are simple first principles that should always be in mind.

" In command prompt coding, "

No such thing. It is obsolete. Now it is recognized that user interfaces are
distinct from "what your software actually does". It's just an interface: be
it CL or GUI. If you don't separate it, you are not a good designer.

You are struggling with the basics. Who is to blame? MS? C++? ....

Tony
 
T

Tony

Apparently you don't "naturally" know how to code. (As some can just sing
like a bird). If you're asking the question, maybe you should either buy a
lotto ticket or prepare for a lifetime of endeavor. There is no
short-circuit to being good at anything. I challenge you to pick up a guitar
and play it. Nuff said. You can't just go and buy ProEngineer and be an
engineer. Those things were created FOR engineers. You have to be one before
you can be one!

Tony
 
T

Tony

Jorgen Grahn said:
Jorgen Grahn said:
[Java] has a garbage collector that makes memory
management easier.
And resource management harder. Some people want GC, but many (most)
do not miss it in everyday C++ programming.

I do not see how the memory manager makes the management
of other resources harder.

Me neither. You are right.
Java does not have language constructs for scope guards
(RAII), but this does not seem to be caused by the existence
of a memory manager. One can imagine a language with both a
memory manager and objects on the stack that are being
destructed when the scope is being exited.

But maybe the hype around the Java GC made it harder to see the
benefits of RAII. RAII certainly makes the benefits of a GC harder to
see.

RAII is not a panacea any more than GC is. They both fail. (Exercise left
for the reader).

Tony
 
R

red floyd

Tony said:
C++ and the Win32 API are on the same level. One is UNIX. One is Windows. :p

So the C++ system I wrote to run under a custom RT executive was Unix?

Wow!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,265
Latest member
TodLarocca

Latest Threads

Top