The first argument const char *format is a format string that contains placeholders marked by % escape character.
By default, C compiler is doesn’t care if you use printf correctly or not. The following unsafe code will compile succesfully without warning or error:
# gcc version 4.9.2
gcc printf_unsafe.c
./a.out
string
The code above seems safe, but it give us unpredictable consequences if a contains placeholder that there are no argument to be formatted. It is possible that it will print a private value from memory.
# gcc version 4.9.2
gcc printf_safe.c
./a.out
string %d
Compiling the unsafe code with -Wformat=2 -Werror flag will prevent you from using printf incorrectly at runtime.
# gcc version 4.9.2
gcc printf_unsafe.c -Wformat=2 -Werror
printf_unsafe.c: In function ‘main’:
printf_unsafe.c:7:2: error: format not a string literal and no format arguments [-Werror=format-security]
printf(a);
^
cc1: all warnings being treated as errors
Scala is my first functional programming language. Recently I wrote a lot of codes in Scala to build a Data processing/analytics and Machine Learning application using Apache Spark.
My first impression was: “Where the hell is line coming from?”. At previous line, there is no definition of line variable/value at all.
I decided to look at Spark API and found the following filter method definition:
def filter(f: (T) ⇒ Boolean): RDD[T]
Return a new RDD containing only the elements that satisfy a predicate.
It turns out that filter method took an argument of boolean function. So, this part should be a boolean function then:
line=>line.contains("Sale Stock")
Ahh interesting, line is the input parameters and it returns a boolean value from line.contains("Sale Stock") one. And that’s part is a Scala Anonymous Function.
It seems, Scala is have a nice syntax to express the anonymous function. I can express previous function as:
Getting work, school and life balance is very hard to do but it is possible.
For me, the balance is about optimizing my time and energy to be used for the right thing. To be able to do that, I need to know what task that need to be done for tomorrow.
In practice, time and energy is a limited resources. Doing the whole thing at once is a bad idea. So splitting task to smaller sub-task is allow me to have a sense of accomplishment. Also, allocating time for break is allow me to keep my energy stable.
I don’t have work, school and life balance yet. But, I feel on the right track to accomplish that.
% scala
Welcome to Scala 2.12.0-M3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_72).
Type in expressions for evaluation. Or try :help.
scala> 2 + 2
res0: Int = 4
Rust programming language comes with traits called Debug as specified in fmt module. We can use this trait to display custom debug information from our struct.
The usage is very straight forward, we just derive debug implementation via #[derive(Debug)] above the struct. For example