C++ anyone?
Posted: 11 Dec 2010 09:45
Recently I ran into some trouble with batch whilst trying to convert the system time to decimal time (metric time).
The problem occured when trying to convert from the milliseconds passed today to the decimal milliseconds passed today (involves dividing by 0.864, only achievable with set /a %DecimalMillisecondsPassedToday%=(%MillisecondsPassedToday%*1000)/864, that extra *1000 causes the error.)
This is due to the fact that the set /a command stores the value as a signed integer (range from -2147483648 to 2147483647) and 86400000000 (the maximum number of milliseconds in a day possible * 1000) is larger than the range of a signed integer, thus causing the equation to output a wrong value after a certain time of day.
I decided that this was reason enough for me to finally enter the realm of C++ programming.
A quick google search of C++ instantly revealed a 'C++ Language Tutorial' (http://www.cplusplus.com/doc/tutorial/) with absolutely all the information a beginner needs. After familiarising myself with the language style and understanding the basics of c++, I had discovered that all of the commands available in batch programming are really just variations of those of it's parent language (c++).
After a few hours of reading, I started building small programs that performed simple tasks. I found it best if I made them from my memory and understanding of various commands rather than copypasta, thus solidifying their uses in my mind.
What amazed me the most was the versatility of the language, the idea that I am not confined by my console, but by my imagination. Commands are stored in header files rather than built in to cmd.exe, meaning that the program becomes standalone, and that the number of commands avaliable to me are endless, with different ones for any conceivable occasion just a google search away.
Another thing that c++ has over batch scripts are the use of compilers/debuggers.
Ever had a piece of code that just wouldnt work, failed to run, or returned some cryptic erorr? Well with c++ those problems are removed with compilers that check your syntax as you type, underlining any mistakes you have made that will cause errors in the finished code AND give you information regarding why they are errors. Also, a debugger will run your code and give you detailed information about any problems that occur during it's test.
The (minor) drawbacks of c++ are it's compile times and the filesize of the finished product. Although compile times are short with short code (usually a few seconds) I can already tell that as code gets bigger and more complex, those times will only increase. This is especially frustrating when you are compiling the same code over and over as you try to get the output just right. The pro of standalonability (totally a word) may be considered outweighed by it's accompanying con - filesize. A few lines of code in batch may be equal to perhaps a few kilobytes, performing that same task in c++ may however be as large as 50 times that size.
Now to the point of this post.
Do you think that my time spent learning batch could have been better spent learning c++?
Do you have any tips for a c++ noob?
Would you consider learning C++ yourself after reading this?
What is the air-speed velocity of an unladen swallow?
Yes or No on metric time (10 hours/100 minutes/100 seconds)?
Is it possible to perform arithmatic with excessively large numbers in batch?
Am I allowed to post some of my c++ code in these forums to compare it to batch?
tldr: Im learning c++ and it is great.
The problem occured when trying to convert from the milliseconds passed today to the decimal milliseconds passed today (involves dividing by 0.864, only achievable with set /a %DecimalMillisecondsPassedToday%=(%MillisecondsPassedToday%*1000)/864, that extra *1000 causes the error.)
This is due to the fact that the set /a command stores the value as a signed integer (range from -2147483648 to 2147483647) and 86400000000 (the maximum number of milliseconds in a day possible * 1000) is larger than the range of a signed integer, thus causing the equation to output a wrong value after a certain time of day.
I decided that this was reason enough for me to finally enter the realm of C++ programming.
A quick google search of C++ instantly revealed a 'C++ Language Tutorial' (http://www.cplusplus.com/doc/tutorial/) with absolutely all the information a beginner needs. After familiarising myself with the language style and understanding the basics of c++, I had discovered that all of the commands available in batch programming are really just variations of those of it's parent language (c++).
After a few hours of reading, I started building small programs that performed simple tasks. I found it best if I made them from my memory and understanding of various commands rather than copypasta, thus solidifying their uses in my mind.
What amazed me the most was the versatility of the language, the idea that I am not confined by my console, but by my imagination. Commands are stored in header files rather than built in to cmd.exe, meaning that the program becomes standalone, and that the number of commands avaliable to me are endless, with different ones for any conceivable occasion just a google search away.
Another thing that c++ has over batch scripts are the use of compilers/debuggers.
Ever had a piece of code that just wouldnt work, failed to run, or returned some cryptic erorr? Well with c++ those problems are removed with compilers that check your syntax as you type, underlining any mistakes you have made that will cause errors in the finished code AND give you information regarding why they are errors. Also, a debugger will run your code and give you detailed information about any problems that occur during it's test.
The (minor) drawbacks of c++ are it's compile times and the filesize of the finished product. Although compile times are short with short code (usually a few seconds) I can already tell that as code gets bigger and more complex, those times will only increase. This is especially frustrating when you are compiling the same code over and over as you try to get the output just right. The pro of standalonability (totally a word) may be considered outweighed by it's accompanying con - filesize. A few lines of code in batch may be equal to perhaps a few kilobytes, performing that same task in c++ may however be as large as 50 times that size.
Now to the point of this post.
Do you think that my time spent learning batch could have been better spent learning c++?
Do you have any tips for a c++ noob?
Would you consider learning C++ yourself after reading this?
What is the air-speed velocity of an unladen swallow?
Yes or No on metric time (10 hours/100 minutes/100 seconds)?
Is it possible to perform arithmatic with excessively large numbers in batch?
Am I allowed to post some of my c++ code in these forums to compare it to batch?
tldr: Im learning c++ and it is great.