Slackware

Slackware
A true linux-distro

Saturday, July 27, 2013

Post 15: Links to helpful information regarding audio processing using SoX.

For the past few days, I have been looking for an open-source software, operable via command line that can help me with a few audio processing goals I need to accomplish. Specifically, I wanted to split any given audio file into multiple sub-files such that there are silences between them.

SoX seems to be a very helpful tool, and perhaps, all that I need.

Friday, July 19, 2013

Post 14: Constructors declared as explicit are preferred to non-explicit ones.

Idiom : Declare constructors as explicit --> Constructors declared as explicit are preferred to non-explicit ones. This prevents unwanted complications and misuse of the constructors. Consider the following piece of code -->

#include <iostream>

using namespace std;

class Ai{
        public:
                int x;
                A(int xx){
                        x=xx;
                }
                void dummy(A a){
                        cout<<a.x<<" of A";
                }
};

class B {
        public:
                int x;
                explicit B(int xx){
                        x=xx;
                }
                void dummy1(B b) {
                        cout<<b.x<<" of B";
                }
};

int main(){
        A a(150);
        B b(200);
        a.dummy(100);
        b.dummy1(500);
}




Note that the constructor of the class B is made explicit.

Consider the statement a.dummy(100), first. Note that the function dummy actually takes in a parameter of class type A, but we are able to pass an integer! What this means is that the integer is cast into an object of class type A by the constructor since, by default, without the extern preamble, it is allowed to do an implicit conversion.


However, with the statement b.dummy1(500),you will see that this does not work because the constructor associated with B is declared explicit. Consequently, when you try to compile this program, you will get the following error -->

g++ explicit.cpp
explicit.cpp: In function 'int main()':
explicit.cpp:31:14: error: no matching function for call to 'B::dummy1(int)'
explicit.cpp:31:14: note: candidate is:
explicit.cpp:22:8: note: void B::dummy1(B)
explicit.cpp:22:8: note:   no known conversion for argument 1 from 'int' to 'B'



Thursday, July 18, 2013

Post 13: Programming idiomatically in C++. You probably do not need it unless you do not have a pressing interest in learning C++.

I realize this blog is primarily meant for Slackware beginners. However, since C++ is programming language I would like to be closely involved it, I thought I might as well share with you important links on how to program idiomatically in C++.

1. http://codereview.stackexchange.com/questions/3714/critique-requested-on-the-program-to-output-the-names-without-repetitions-with-t -->

Story of a person who got rejected a job offer due to, in all likelihood, making superfluous use of the C++ programming language and not adhering to the C++ programming paradigm. Experts have reviewed his code, dissected it and advised against usages of certain C++ features which would seem innocuous to most naive C=+ programmers.


2. http://stackoverflow.com/tags/c%2b%2b/info -->

This page is a portal and contains reading lists, FAQ sections, links to C++-related questions asked on Stackoverflow and other sibling-forums, links to softwares and other external resources.


Certain idioms which you may or may not know about and, adhering to which, contributes to programming in C++ style proper can be found on this blog.