Python or C++

Associate
Joined
30 Nov 2011
Posts
1,131
Hi all,

I fancy having a go at trying to learn a big of programming.

I have watched a few videos on both and obviously Python is a lot easier as its syntax is almost as easy as HTML haha.

This is purely just for some fun.

All the videos I have watched just do basic things like add number and get the user to enter a name etc or a very basic game. Nothing that is actually useful.

I would like to try and make a program that will kill/terminate certain programs running on my PC in the background before I start a game. I normally manually close at least 3 things and thought it would be a nice little challenge.

Obviously I do not know where to start or even if Python can do this? I assume C++ can but is obviously a steeper learning curve - although picking up other languages from there must be much easier.

Im hoping I can attach a script to a game .exe for example that will terminate the programs specified?

Im sure this can actually be done in windows Command line no doubt.

Any thoughts is this a futile exercise?

Thanks,
Sean
 
Man of Honour
Joined
13 Oct 2006
Posts
91,147
For stuff like that you need to start learning how to use dll calls - the relevant functions are part of the various Windows dlls - I think with Python you'd interface with kernel32 and windll/psapi.
 
Associate
OP
Joined
30 Nov 2011
Posts
1,131
For stuff like that you need to start learning how to use dll calls - the relevant functions are part of the various Windows dlls - I think with Python you'd interface with kernel32 and windll/psapi.

Ooh sounds a bit advanced, ill have a google. I assume you know some programming language(s)?

Any examples of something useful that can be done without to much knowledge?

Thanks,
Sean
 
Man of Honour
Joined
13 Oct 2006
Posts
91,147
An example of the kind of programming to get a running program or process and terminate it here for C++ https://stackoverflow.com/questions/865152/how-can-i-get-a-process-handle-by-its-name-in-c there are a few different approaches to how to do it depending on whether it is a program with a Window or a background process, etc.

I've been programming since the release of QuickBASIC 4.5 in like 1988 heh.

EDIT: I would actually suggest starting with a simple 2D game - it is easier to learn the fundamentals than trying to work with the Windows system functions :s
 
Soldato
Joined
25 Jun 2011
Posts
5,468
Location
Yorkshire and proud of it!
Hi all,

I fancy having a go at trying to learn a big of programming.

I have watched a few videos on both and obviously Python is a lot easier as its syntax is almost as easy as HTML haha.

This is purely just for some fun.

All the videos I have watched just do basic things like add number and get the user to enter a name etc or a very basic game. Nothing that is actually useful.

I would like to try and make a program that will kill/terminate certain programs running on my PC in the background before I start a game. I normally manually close at least 3 things and thought it would be a nice little challenge.

Obviously I do not know where to start or even if Python can do this? I assume C++ can but is obviously a steeper learning curve - although picking up other languages from there must be much easier.

Im hoping I can attach a script to a game .exe for example that will terminate the programs specified?

Im sure this can actually be done in windows Command line no doubt.

Any thoughts is this a futile exercise?

Thanks,
Sean

Well the Python syntax is elegant, certainly. But there's a LOT more to it than HTML. ;) One is a mark-up language that describes how to display data. The other is a programming language!

Of the two, you're correct - Python is a lot easier to learn than C++. That's not to say it's better. Learning curve is only one aspect of a programming language. But before you decide to decide between these two, let me check you know the difference between C++ and C#. They're similar but different and you might find C# a little easier to begin with because it's got a strong userbase and environment focused on Windows and the sort of thing you're talking about doing. Specifically, it's got excellent integration with .NET which is a Microsoft Framework well suited to accomplishing things on Windows. So a better question MIGHT be Python vs. C#, rather than Python vs. C++. Of course C++ is older and more multi-platform (popular on Linux as well as Windows).

I think what you've decided to do is actually more complex than you realise because you'll be learning TWO technologies at once, rather than just one. You have to learn the language (programming), but you'll also have to learn your way around the Windows APIs as well. Neither is super simple so doing both at once might be frustrating. Maybe.

If I wanted to write a program that closed Windows applications, I personally would do it in Powershell. Powershell is very powerful and contains many modern programming functions. It's also often used for this sort of thing. You could fire up ISE (use this rather than the standard Powershell shell because it's far better) right now and start writing your program closer. Alternately, you could start with a tutorial for Python or C# and focus on learning the basics of the language. Both are free and have plenty of tutorials. For C#, you'd normally install Visual Studio (there's a free community version which is excellent). For Python, you'd just install it and start typing out Python in your favourite text editor (Atom is a good free one for editing. So is Visual Code, on Windows).

If you want to learn programming and you're completely new to it and like Python, you might want to look at Django. It's a great way to immediately start producing an actual working thing. For C#, perhaps follow some of the .NET Core tutorials. It's a great language but it IS harder to learn. As is C++ if you wanted to stick with your original idea.

Whichever you choose, there'll be a bit of a frustrating start getting everything you need installed and working together (well, unless you take my suggestion to start with PowerShell in which case everything is already there for you). But don't let it discourage you. Once you've learned to program, there are endless possibilities and it's a lot of fun. :)

I hope this helped.
 
Associate
Joined
18 Oct 2002
Posts
1,752
Location
Southern England
I'm sitting here looking to learn something new. I've been coding on various flavours of Basic since my Atari 800xl days in the 80's. Did a small amount of COBOL on mainframe during the mid 80's and then started coding in VB.NET and VBA in the last 10 years or so.

I'm tempted by C++ simply because it's always been on the list for me to learn but C# and Python are also tempting too.

So would python by the next natural step or should I just take leap and hit C++ ?
 
Soldato
Joined
25 Jun 2011
Posts
5,468
Location
Yorkshire and proud of it!
I'm sitting here looking to learn something new. I've been coding on various flavours of Basic since my Atari 800xl days in the 80's. Did a small amount of COBOL on mainframe during the mid 80's and then started coding in VB.NET and VBA in the last 10 years or so.

I'm tempted by C++ simply because it's always been on the list for me to learn but C# and Python are also tempting too.

So would python by the next natural step or should I just take leap and hit C++ ?

To learn any of these three to a professional level is a significant task. So if you have an end goal in mind, you might want to focus on whichever language best suits your end purpose. They each have different areas they are either best at or most used for. But if your goal is simply to learn and to become a more serious programmer, then any of these three could work. I'll list out some very brief pros and cons:
  • Python. Elegant and most certainly the smoothest learning curve of the three. Modern in design, you will learn good principles. It's also good for going from zero to "I made something" relatively quickly (you might want to check out Django, also). It is not the most "powerful" language though, in certain senses.
  • C++. The hoary old grand-daddy of the three. And I would say the hardest of the three to learn. It is very powerful. It is also applicable to many different environments - Windows, Linux, et al. There are multiple versions and somewhat less modern. It's also hard to entirely separate from its environment and libraries. Like yes - C++ on Linux is the same as C++ on Windows. But the libraries you will use may be different. Just because you learned to drive a car in London, it doesn't mean you can get around easily in Paris, even with the same car. But still, it's powerful and broad in its application.
  • C# The younger cousin of C++ (and also Java). It's got a lot of modern features, I would say it's easier to learn than C++ and there are a lot of frameworks and tools that mean you can get up and running kind of quickly. Still harder to learn than Python though. It's a quite beautiful language. But it's large and its sophistication makes it hard to grasp intuitively until you've gone quite far with it.
There's also PHP which is an excellent language to learn, very popular and takes you from nothing to "I'm making websites" pretty darn quickly. You'll learn some awful habits, though! :)

Honestly, if you're asking me C++ or Python, I'd say Python. You'll have a much easier time of it and if you have an intent to become good in a professional sense, C++ will take you a long time. If you're asking me between C# and Python, I'd return to the question of what your end goal is.

You mention COBOL and VB (various types). You'll find C# and Python both very different to both of these, with a heavy emphasis on Object-Oriented Design and modern practices like Interfaces, Decorators and other things that will likely be unfamiliar to you. Learning either of these languages will be just as much learning modern theory as it will be learning syntax.
 
Man of Honour
Joined
13 Oct 2006
Posts
91,147
I'm sitting here looking to learn something new. I've been coding on various flavours of Basic since my Atari 800xl days in the 80's. Did a small amount of COBOL on mainframe during the mid 80's and then started coding in VB.NET and VBA in the last 10 years or so.

I'm tempted by C++ simply because it's always been on the list for me to learn but C# and Python are also tempting too.

So would python by the next natural step or should I just take leap and hit C++ ?

I usually recommend Python to people who haven't gone through the whole dabbling in BASIC, etc. phase - if you've got some coding experience in general I'd say look towards C++, C# or something like that or more specialised if you had a purpose in mind i.e. going into a career in something.
 
Soldato
Joined
25 Jun 2011
Posts
5,468
Location
Yorkshire and proud of it!
I usually recommend Python to people who haven't gone through the whole dabbling in BASIC, etc. phase

Python still offers a lot even if you have dabbled in BASIC, Cobol, etc. Python will teach you modern object-orientated software approaches because the whole language is structured around it. BASIC or Cobol will teach you syntax (ugly syntax ;) ) but nothing about structure of a program - classes, inheritance, etc. That said, it's not perfect in this regard, either. It has multiple inheritance and therefore (afaik), never introduced interfaces.
 
Man of Honour
Joined
19 Oct 2002
Posts
29,524
Location
Surrey
Python will be a lot easier to learn and a lot faster to write. C++ will be harder to learn and is a much more verbose language. Personally I would choose Python for this task. But if the intention is to learn other languages later then the syntax of C++ is far closer to most modern languages because they tend to derive from the C syntax.
 
Soldato
Joined
6 Mar 2008
Posts
10,078
Location
Stoke area
if you want to become a programmer professionally, I've always been told to start with C, then C++. C will teach you everything you need.

However, if you're just looking to dabble, c# at a push but I'd go with Python. Look for the Python Programming Society on Facebook or the Python Programming Language group. Lots of info but the admins can be a little OTT with the hammer, PPS is more relaxed and noob friendly but that's because I'm the main admin and only a mod on PPL.

There are many Python resources out there which is a good and a bad thing, bad because you get a lot of **** tutorials posted by people with little or no experience hoping they'll get some Youtube kudos.
 
Man of Honour
Joined
13 Oct 2006
Posts
91,147
There are many Python resources out there which is a good and a bad thing, bad because you get a lot of **** tutorials posted by people with little or no experience hoping they'll get some Youtube kudos.

On the other hand if you have any hope of being any good at programming then you should be able to work out pretty quickly the good from the bad and learn from it as well. I hate to be an elitest/snob but I really wish people wouldn't go into programming who can only do it as they've been taught and are lost the moment they step off the established path.

C I have very mixed feelings about - some things are just so frustrating and obscure but the power of it in certain aspects is also quite impressive - for instance complex use of structures can achieve some crazy stuff with data handling.
 
Last edited:
Soldato
Joined
17 Jun 2012
Posts
11,259
C++ can be a bit daunting at the beginning, pointers and references throw people off if not taught properly and simply. Classes can be confusing, the real problems are when your code base gets large, it's difficult keeping track of what your doing. Remember though these are languages and can really do little by themselves, you can only really do basic console calculations or file I/O. To do any GUI stuff you need to either use the win32 API or some third party toolkit such as Qt. As for games you would need to either learn openGl or DirectX which is when things get proper tricky.

Most people nowadays use engine such as unity or unreal.

In the old days most things revolved around efficiency. People would use say c++ with inline ASM for max efficiency. Nowadays this isn't such a problem as pcs are powerful and lots of ram.
 
Soldato
Joined
6 Mar 2008
Posts
10,078
Location
Stoke area
On the other hand if you have any hope of being any good at programming then you should be able to work out pretty quickly the good from the bad and learn from it as well. I hate to be an elitest/snob but I really wish people wouldn't go into programming who can only do it as they've been taught and are lost the moment they step off the established path.

C I have very mixed feelings about - some things are just so frustrating and obscure but the power of it in certain aspects is also quite impressive - for instance complex use of structures can achieve some crazy stuff with data handling.

I think if you've no experience at all you take what you see as face value, and although it may not be a terrible tutorial and will achieve what it's meant too it may be full of bad practices that a noob wouldn't know was bad.
 
Associate
OP
Joined
30 Nov 2011
Posts
1,131
Lots of good info here, will take a looks at some of the suggestions. Any of you have any programs you have made that you could share?

Looks like a few of you have lots of experience.
 
Soldato
Joined
6 Mar 2008
Posts
10,078
Location
Stoke area
I use Python for little things, such as web scraping, pulling public XML feeds from websites and collecting information, even some basic programs to scramble strings to make codes for my 7 year old.

C# I dabble with for work as it's easier, so we have a check twice a day to see that 30 ish files have been created and moved into one of 2 output folders where they are then sent from. That check can take 30-75 minutes depending on the person and the number of files. My script does this in a console instantly.

It used to just do that day's, then I created the ability to pull yesterday's files, that created more issues with Thursday only files. I'm fixing that and have some more improvements to make.
 
Man of Honour
Joined
13 Oct 2006
Posts
91,147
Any of you have any programs you have made that you could share?

I can share all kinds of useless snippets of code hah for instance my first and only usage of Perl

Code:
#!/usr/bin/perl
# file: records.pl

#use strict

use IO::Socket::INET;

$crlf="\r\n";

$TMip=$ARGV[0];;
$TMport=$ARGV[1];
$TMpass=$ARGV[2];
$TMmatch=$ARGV[3];


sub str2ord {
    my $out;
    my $LOOP_COUNT=length(@_[0]);
    for ($count=0; $count <= $LOOP_COUNT; $count++ ){
        $out.="[".ord(substr(@_[0],$count,1))."]";
    }
    return $out;
}

sub int2byte4 {
        my $inval=@_[0];
        my $out .= chr($inval & 255);
        $out .= chr(($inval >> 8) & 255);
        $out .= chr(($inval >> 16) & 255);
        $out .= chr(($inval >> 24) & 255);

        return $out;
}

sub bytes2int {
        my $inval=@_[0];

        $byte1 = ord(substr($inval,0,1));
        $byte2 = ord(substr($inval,1,1));
        $byte3 = ord(substr($inval,2,1));
        $byte4 = ord(substr($inval,3,1)); # doesn't seem to throw up an error i$

        return ($byte1 | ($byte2 << 8) | ($byte3 << 16) | ($byte4 << 24));
}

sub xmlAheader {
    return "<?xml version=".chr(34)."1.0".chr(34)."?>";
}

sub xmlAcall {
    return "<methodCall><methodName>".@_[0]."</methodName>";
}

sub xmlAparams {
    return "<params>";
}

sub xmlAparam {
    return "<param>";
}

sub xmlAint {
    return "<value><int>".@_[0]."</int></value>";
}

sub xmlAstr {
    return "<value><string>".@_[0]."</string></value>";
}

sub xmlAbool {
    return "<value><boolean>".@_[0]."</boolean></value>";
}

sub xmlAfloat {
    return "<value><double>".@_[0]."</double></value>";
}

sub xmlCparam {
    return "</param>";
}

sub xmlCparams {
    return "</params>";
}

sub xmlCcall {
    return "</methodCall>";
}

sub rpcSend {
    my $invar=@_[0];
    my $outvar=int2byte4(length($invar)).chr(255).chr(255).chr(255).chr(255).$invar;
    $sock->print($outvar);
}


$sock=IO::Socket::INET->new(PeerAddr => $TMip,PeerPort => $TMport,Proto => 'tcp');
die "Socket creation failed with: $!\n" unless $sock;

$temp=xmlAheader;
$temp.=xmlAcall("Authenticate");
    $temp.=xmlAparams;
        $temp.=xmlAparam;
        $temp.=xmlAstr("Admin");
        $temp.=xmlCparam;

        $temp.=xmlAparam;
        $temp.=xmlAstr($TMpass);
        $temp.=xmlCparam;
    $temp.=xmlCparams;
$temp.=xmlCcall;

rpcSend($temp);

while () {
    #$temp=$sock->getline();
    #if ($temp) {
    #    print $out."\n";
    #}
    read $sock,$out,16;
        #print str2ord($out)."\n";
        print $out."\n";
}

close($sock);


Hand crafting XML RPC calls for Trackmania Nations Forever server administration (there were reasons for not using an existing XML library). Probably those that actually use Perl can see all kinds of issues hah. My coding has come on a long way since then but I love how unreadable Perl is at first glance.
 
Man of Honour
Joined
19 Oct 2002
Posts
29,524
Location
Surrey
This is a useful video because it shows some of the advantages and disadvantages of each language with some example code. Note how simple the python code is compared to the equivalent C++, but at the cost of speed.

 
Back
Top Bottom