Today's Question:  What does your personal desk look like?        GIVE A SHOUT

SEARCH KEYWORD -- Code nesting



  Reducing Code Nesting

"This guy’s code sucks!" It’s something we’ve all said or thought when we run into code we don’t like. Sometimes it’s because it’s buggy, sometimes it’s because it conforms to a style we don’t like, and sometimes it’s because it just feels wrong. Recently I found myself thinking this, and automatically jumping to the conclusion that the developer who wrote it was a novice. The code had a distinct property that I dislike: lots of ...

   Code nesting,Readability,Maintainability,Reduction     2012-01-02 08:13:46

  do {...} while (0) in macros

If you are a C programmer, you must be familiar with macros. They are powerful and can help you ease your work if used correctly. However, if you don't define macros carefully, they may bite you and drive you crazy. In many C programs, you may see a special macro definition which may seem not so straightforward. Here is one example: #define __set_task_state(tsk, state_value) \ do { (tsk)->state = (state_value); } while (0) There are many this kind of macros which uses do{...}while(0)...

   C,macro,C++     2014-01-23 07:16:13

  Short SASS tutorial

If you learned CSS before, you should know that CSS is not a programming language. You can use it to design webpage style, but you cannot use it for programming, i.e, CSS is what designer uses, not what programmer uses. Programmer may think that CSS is very troublesome, it has no variables, no conditional statements, it just allows line-by-line description of HTML elementsLuckily, CSS preprocessor appear which makes CSS programmable. The general idea of CSS preprocessor is using a programming la...

   CSS,SASS,programmable,variable,condition,comment     2012-06-22 08:38:18

  A Python assignment trap

Python has no assignment, it only has reference. Assume, we have following code snippet: >>> values = [0, 1, 2] >>> values[1] = values >>> values [0, [...], 2] Why the result is not [0, [0, 1, 2], 2], instead it goes into an infinite loop? To understand this, we need to understand some basics about Python. Python has no variables, it only has labels. When we run: values = [0, 1, 2] Python will first create a list object [0,1,2], then it labels it as values. If we later...

   Python,Assignment,Trap,Shallow copy     2013-07-19 22:08:36

  <=> operator in MySQL

Have you ever seen "<=>" in a SQL query while using MySQL? Does it mean less and equals to and greater than? Actually if you consider it as the union of <= and =>, great, you are close to it. This is one form of equal operator in MySQL, it has the similar meaning to the = operator with some subtle difference. According to MySQL documentation, <=> is NULL-safe equal. This operator performs an equality comparison like the = operator, but returns 1 rather than NULL if both operand...

   MySQL,NULL safe,<=>     2014-03-24 06:23:22

  A Perl Regular Expression That Matches Prime Numbers

perl -lne '(1x$_) =~ /^1?$|^(11+?)\1+$/ || print "$_ is prime"' Can you figure out how it works? I give an explanation below, but try to figure it out yourself. Here is what happens when you run it: $ perl -lne '(1x$_) =~ /^1?$|^(11+?)\1+$/ || print "$_ is prime"' 1 2 2 is prime 3 3 is prime 4 5 5 is prime 6 7 7 is prime 8 9 10 11 11 is prime Here is how it works. First, the number is converted in its unary representation by (1x$_). For example, the number 5 gets converted into 1x5, which is ...

   Perl,Regex,Regular expression,Prime number,One line     2011-12-26 08:42:00

  Sass Style Guide: A Sass Tutorial on How to Write Better CSS Code

Writing consistent and readable CSS that will scale well is a challenging process. Especially when the style sheets are getting larger, more complex, and harder to maintain. One of the tools available to developers to write better CSS are preprocessors. A preprocessor is a program that takes one type of data and converts it to another type of data, and in our case CSS preprocessors are preprocessing languages which are compiled to CSS. There are many CSS preprocessors that front-end develop...

   CSS,SASS,TUTORIAL     2015-09-17 06:40:47

  C/C++ Pointer Declaration Syntax – It makes sense!

I never really liked the way pointers are declared in C/C++: int *a, *b, *c; // a, b and c are pointers to int The reason is that I am used to reading variable declarations as MyType myVar1, myVar2, myVar3; and I always read “int*” as the type “integer pointer”. I therefore wanted the following int* a, b, c; // a is a pointer to int, b and c are ints to mean that a, b and c all were of type int*, i.e. pointers to int. and I therefore found it slightly a...

   C,Pointer,Declaration,Attempt     2012-02-22 05:43:58

  Paint messages will come in as fast as you let them

There is a class of messages which are generated on demand rather than explicitly posted into a message queue. If you call Get­Message or Peek­Message and the queue is empty, then the window manager will look to see if one of these generated-on-demand messages is due, messages like WM_TIMER, WM_MOUSE­MOVE, and WM_PAINT. Neil wonders, "In that program that called Invalidate­Rect 100,000 times, how many paint messages were generated?" The Zen answer to this question is "Yes." A ...

   WM_PAINT,paint message,work,Mouse move     2011-12-21 09:37:14

  About go get and go install in Go 1.16

Go version 1.16 beta1 has been released on 18 Dec 2020, major features of Go 1.16 have been finalized with this beta release. Many people are discussing about the support of Apple M1, however, this post will not cover this topic. Instead the focus will be on go get and go install changes. There are lots of changes related to modules in Go 1.16, the details can be found in the release note. Below are some of the key highlights. GO111MODULE is on by default, if wanna keep old behavior, needs...

   GOLANG,GO 1.16,GO INSTALL     2020-12-26 00:26:58