Beautiful Code Runs Faster

  • Blog
  • About
A quick trainning plan of software developers 04/12/2012
0 Comments
 
图片
It's quite common that the company hired a group of new engineers to expand the team. Then how to train them so that they adapt themselves well in the company culture,  understand the business quickly, and produce quality codes. Here's some tips.

1. Inform everyone duties of each division and individual, and principles of time management. This can quickly make everyone be self organized and motivated.

2. The business logic. All company knows how to inform engineers this part. Usually it's done by ask the new engineers to use the product.

3. Coding style. Soon after an engineer is hired he'll begin to code. Then making sure everyone work in the same coding style can help greatly on creat code that fit well to the company's existing system.

3. Code refactoring, Object oriented design, and the use of basic frameworks. Because engineers are from different companies, with different backgroud, this train is crucial for creating reusable and consistent code.

Add Comment
 
Threadpool implementations for C++ 03/12/2012
0 Comments
 
Picture
Nearly all morden frameworks provide built-in thread pool implementation. However C++ does't. Here's a list of implementations of thread pool in C++.

Threadpool
http://threadpool.sourceforge.net
threadpool is a cross-platform C++ thread pool library based on Boost. The threadpool library provides a convenient way for dispatching asynchronous tasks. Pools can be customized, managed dynamically and easily integrated into your software. The library is used by several commercial server applicaions and an handle high work load without problems.

Sample code:

#include "threadpool.hpp"
using namespace boost::threadpool;

void normal_task();
void important_task();

void execute_prioritized()
{
  // Create prioritized thread pool container without any threads.
  scoped_pool<prio_pool, 0> tp;

  // Add some tasks to the pool.
  tp += prio_task_func(5,   &normal_task);
  tp += prio_task_func(100, &important_task);
  tp += prio_task_func(7,   &normal_task);

  // Add the some threads to the pool. This will start the execution of the tasks.
  tp->resize(2);

  // The tasks are processed according to their priority:
  // important_task(100), nonrelevant_task(7), nonrelevant_task(5).

  tp->wait();
  // Now all tasks are finished and the pool will be destroyed safely when tp goes out of scope.
}

ThreadPool
http://www.hlnum.org/english/projects/tools/threadpool/index.html
Quite simple implementation based on lib_pthread. You can base your code on it and it's very likely some further modification is required. As is introduced in its homepage, it's:

"An implementation of a thread-pool based on POSIX-threads. It builds a pool of p threads which are blocked until a job was given to the pool. Then an idle thread is chosen and the job is executed at this thread. If no idle thread is available, the pool blocks until one of the running jobs terminates."

ffead-cpp
http://code.google.com/p/ffead-cpp/
It's an ambitious project that aims to bring C++ to the world of web development. As is stated in it's introduction page:

"The framework is developed for rapid development of Enterprise application on the C++ platform. It is a c++ web framework, c++ application framework, c++ rest framework and c++ soap framework all bundled into one. It consists of the following and is currently implemented for LINUX/WINDOWS(Cygwin). It is the first and only C++ Application framework to provide non-intrusive Dependency Injection and Business Driven Component Logic and POCO based Development. Most of the features are controlled by configuration files."

poco c++ libraries
http://pocoproject.org/
Poco is a framework written in modern, standard ansi C++ using C++ standard library. The framework seems perfectly complete(compression, data access, ssl, crypto, xml, threading, ipc - Anything you could think of in application development, it incudes.) It uses Boost license, and seems has lots of users.

Windows API
http://msdn.microsoft.com/en-us/library/windows/desktop/ms686766%28v=vs.85%29.aspx

Supprisingly, Windows provides API for thread-pool management.And they have two sets of them. There was one shipped with Windows XP, and then in Windows Vista they upgrade the API by providing the second set.

libcurl
http://curl.haxx.se/libcurl/c/curl_multi_perform.html

If you are planning to use a thread-pool along with curl. The answer is, you don't need a thread-pool! This function provides all what you need. With asynchronous socket you can handle many connections with one thread, and curl has perfect support for this. It's fast, robust and handy.

Now smile :)
Add Comment
 
首都博物馆 02/05/2012
0 Comments
 
昨晚上约了去首都博物馆。早上9点就出去了。同行这人说话相当直爽。聊天真是令人很有乐趣。博物馆也是相当的有看头,外墙贴的是数千年间地图变迁。内测则是各种古代器具,见识了古代有钱人的生活。有气象雄浑的书法,有工笔细描的国画花草,绘制繁复的玉石桌面,金丝搂制的皇帝的帽子,和精巧小钟组合的扇子,五彩斑斓的瓷器,薄如蝉翼的玉碗,表面浮雕精致无伦的首饰盒,莹润洁白的象牙文具盒,毛笔。。。果然百工之技,只是为了那么几户大人物家里精致的摆设。

看了古代各种器具装饰,古代的工匠技艺之出众,真是令人叹为观止。这么多能工巧匠,各路高人,或者为了发家致富,或者为了附庸风雅,或者为了讨好父亲/美女/上司,逐渐技艺精进,居然创造出这么神奇绚烂的世界,真是令人感叹。

不过古代这些东西,说实话都是首重装饰,略重舒适。一个椅子精雕细镂,坐着不咯得慌?还有一个枕头居然两头嵌了牛角,让人担心会不会捅瞎双眼?到了今天,大家用的东西不仅造型美观,且更加注重舒适和各种健康条件。在用的东西上只要是稍微经济宽裕的,应该可以超越古代的贵族了吧。但是古代的贵族有大批下人伺候,饮食起居都有人伺候,且有高明御医各种把脉,这个还是只有中南海的官员才能享用。所以虽然时代前进,到底还是贵贱有别。我们所引以为豪的最文明的今天,在漫漫历史长河中恐怕和前朝各代不会有太大区别。


照片见我的flickr~
Add Comment
 
The trip to Harbin 01/03/2012
0 Comments
 
Obviously I'm not the kind of people who can enjoy a long trip - I'm so poor at planning it. But I went there! The aim of the trip is actually for some life stuff which the readers won't be interested. Anyway, I went there and traveled in the city for 2 days. And most part of the journey was nice.

We launched on Dec. 31 at night, spent the night in train, and arrived the second morning. It was really cold outside (-20 C), soon after we left the train my face was almost frozen. The air wasn't nice. You can smell the dusts from vehicles - even when you are inside a cab, which takes us to the place where we lived for 2 days.
The hotel was beside Songhua River. On our way to the hotel, we met Zheng Lvcheng Memorial Hall.
Picture
photos of the man
Picture
Should be him ... oh my Music teacher :D
Songhua River is big. In it it's all ice. No water. There's even cars moving above it, and there doesn't seem to be any problem. Here's some photos taken there.
Picture
Building with ice, they are everywhere in Harbin
Picture
On the river
Picture
Seems to be a cake
In the afternoon we went to Sofia Church. The church was surrounded by shopping malls but it manage to keep it's regional style. There're many pidgins on the roof. For a visit in the church you need to buy a ticket with 30 RMB. We bought and we entered. In the church it's like a big lobby, there were many people inside. A group of singers were singing on the platform in the center. I believe they sing well, though it's definitely not for me.
On the walls there're pictures telling the history of Harbin, the city in the very North of China, but grows to one of the 'second-biggest' cities in the country. From the pictures you know that there used to be a district in the city for Russian. But now you see less and less Russian. Nobody knows where they went. However there's still a Russian dacnging show. The cab driver said it's fantastic. However I never saw. - OMG, what a unfortunate trip.
BTW I didn't see many beautiful Russian girls :(
We had dinner at a restaurant in Center Avenue. It was a Russian restaurant. The food was good, but the price is no less than what's in Beijing: 400 RMB for 5 persons, including 4 adults and one 3-year-old girl, all simple Russian foods. So I guess the best place to enjoy nice food all over the world is still Beijing.
Picture
The restaurant, love it because it spells like 'tactoth'
Picture
The soup
Picture
Western Cold Steak?
Picture
Violin on the wall
Picture
After the meal, we saw this
Then it came the next. The original plan was to visit Sun Island. Then when we arrived there, we were told that the price is 240RMB per person. Usually it's 30RMB. The reason why it's much expensive is that there's a 'Snow sculpture show'. Many people decided to leave and we are among them of cause - we are poor, stingy, and lacks a taste of arts.
So we turn to Pole Show (130 RMB for each person, kids doesn't need a ticket). It's really a fantastic place.
Picture
promise me that you recognized me~
Picture
the two fat boys
Picture
the artificial scene is nice too
Picture
“my land, go away!”
Picture
Please .. let me be there
Picture
swimming penguin
Picture
city penguins
Picture
flying fish
Picture
'you human is boring'
Picture
'seriously'
Picture
it's a real shark.. OMG, hope the glass is not made in china
For some reason my journey stopped after I visited the Pole Show. I also bought some nice stuff from Russian Shops, which is everywhere in the city.
Picture
things to give out~ it's not expensive but i'm a great friend, haha
Add Comment
 
In my 5th year as a software engineer 12/21/2011
0 Comments
 
Picture
When 8 years ago I was in college I never expected my self to be a programmer. When 4 years ago I started working for Autodesk as a software engineer I never expected it to be my life time career. So I'm quite surprised that I've being working as a software engineer for nearly 5 years and am determined to do it really well. 5 years, it's long, and thing happen in between teaches you something,  here I list some conclusions.
1. Always do projects that brings most cash.
I started doing projects on TopCoder when I was in my last Year in Tongji University. The payment was actually excellent. I got 20k per month, even now after tax I don't make as much. However I choose to go to a big Corp. (Autodesk) to be a 'decent' software engineer. Sucks! - I don't mean Autodesk is bad, it an excellent company. However it's not the best for me, but I went there!

The logic is simple, people are willing to pay more cash for some project, it's because the project is more valuable. You should simply work on valuable project because then the experience you got is for more valuable things.

2. Impress your co-workers.
I believe that excellent engineers should earn big cash. Because of their solid programming skills, that can quickly build systems that seldom has bugs, are maintainable, robust, and create great value to the world. As long as there's someone realize some needs from the market, gather smart engineers to build them become crucial.

Your coworkers, knowing themselves to be excellent people, are always seeking this kind of market needs, and when they find it, make sure they believes you to be highly professional and have great team spirit.

3. When you've finally impressed someone, cherish it.

An valuable impression costs time and hard work to build up, and easy to destroy. I've lost something really big, then I know it's so valuable.

To be trusted, you must have been watched on for a few years. So always cherish things that you build up with time.

4. Quit bad companies ASAP.
Yes they do can manage to make the business run, because the boss is already rich and important. But what about you? Are you rich enough to kill time in this way? Do you enjoy wasting your time with no joy?

Don't judge a company by corporate culture/..., just by money. If it's about future money, make sure you can get it.
Add Comment
 
Will expensive rent make teleworking more popular? 10/08/2011
0 Comments
 
Picture
i now live dozens of meters away from here -_-
I've recently moved to Sanlitun, not because I love night life, nor do I go there to save commute time - I send more time on the road actually (and unfortunately). I go there just because everywhere in Beijing has similarly high rent, and surprising enough, the rent different between Sanlitun and other places are minor.

So it reminds me that - as I know, most people want to live a family life. I'm like those home builders. I want to make a powerful, comfortable and beautiful home. To be such it needs to be BIG, so big that it can hold lots of things I buy and build. But the expensive house price makes the dream impossible. It upsets me.

Each time I feels this frustration, I hope I'm teleworking. In that way I can connect myself to the most developed economy, and yet enjoy a peaceful family life, do some gardening/cooking/etc(which is absolutely a luxury for salary slaves in the city). I'll buy a car and actually drive it (In Beijing of cause it's impossible, there are too many.), and fixing it of cause will become a big source of fun too.

This will be perfect! I believe in the future jobs that doesn't require employees to work in an office will provide such flexibility. More and more people will be working in front of a laptop in their garden, on the roof, in the kitchen(to smell the food his wife is cooking), or even in bath room?

Probably I should build some software to make teleworking easier, for the world :D
Add Comment
 
刘学虎在珠海的神奇经历 08/02/2011
0 Comments
 
Picture
“我最近在这边遇到的稀奇古怪的事情太多了”。

“这边的台风实在是太奇怪了,说来就来,而且台风出现的时候最常看到的就是一边天气晴朗,离不了100米的地方却在下雨,台风出现的时候一天要下好几次雨。”

“有一天我们有公司组织的篮球赛,我们在大街上走的时候,突然出现了很多女的,穿着短裙,上面是学生的打扮,在发传单,哈哈哈哈,你不知道他们传单上面写的是什么。。。 专车接送。。。。服务一流。。。 哈哈哈哈,据说东莞的话要更加夸张一些!我以前在西安有听到过这种事情,但是这种成群结队在大街上发传单的还真是少见”

“这边的房子都建的很漂亮,房子的话大概4000+一平米。除此之外一切都让人很失望。只有很少的一部分像大城市如北京上海那样,最多的地方都和通渭县没什么两样,我现在住的地方前面就有一个鱼塘。”

“我做了几次面膜,脸上长了一个很大的痘痘。”

"这些南方人,说话根本就听不清楚,他们应该也是在讲普通话,但是和我习惯的实在是区别太大。而且你再问他们,他们就不说了。唉!这帮南方人!我现在只要遇到一个长江以北的,便开始认老乡。上次遇到两个河南的,我就说我河南话完全听懂,对那地方可熟悉了。那两个人也非常激动,于是一个劲的讲起了河南话,你知道我根本就听不懂河南话,所以我很尴尬。”

刘学虎的浪漫事件1:

“上次遇到一个女的,我还蛮喜欢的,我们培训的时候在一起。然后我俩聊得蛮投缘的:她一个劲的和我讲她对文学的大量观点,我正好也能说一点附和附和。我当时犯了一个很大的错误就是没有要电话。因为第二天我们就分部门培训了,所以就没有再看到她。不过我知道她工作的地方在中山”。

刘学良:“那你周末的时候应该去那边公司看看,说不定能再遇到,你要抓紧时间,别被人抢了先。”

刘学虎:“嗯,说的是,不过名字我知道,我可以想些办法”。

Finally:
刘学虎,祝你一切顺利!(你知道我说‘一切’的时候,都包含了什么 :D)
Add Comment
 
(转)从裸婚时代和豪斯医生看中美民众的智商差距 07/28/2011
0 Comments
 
此文不能不转
最近一个79年生的漂亮的妈妈同事大力向我推荐裸婚时代,她自己和公婆一家住着近200平米的徐家汇大房子,看了裸婚时代后很庆幸自己当年没有裸婚,如今自己卧室的主卫都有20平米,比人家小房子型的客厅 还要大,家务和孩子都有老人管着,自己赚的钱全拿来名牌衣物,活得很滋润.我连续看了十集后和我最喜欢的7季全看完的豪斯医生,BONES等美剧 做了一下对比 ,结论是中美的电视剧编导和观众群体的智商差距已大于60了,中国这边主流还是IQ70的时候,人家已经130了.

首先裸婚时代已经不算是中国制作水平差的一类电视剧 了,导演曾经导过双面胶和蜗居,前两部剧本 是六六的小说改编的,到底是实力强,不愧为中国最一流的现代 题材剧作者,而这部输就最先输在原小说的肤浅上了.首先只抓住了裸婚 的这个词的流行性却没深入本质去诠释,挖掘80后群体裸婚主流人群的特点,无奈,和成因.

裸婚时代里明显的BUG不下一百个,只谈几个主要的,首先男女主角选在两个北京本地人身上就不妥当 ,裸婚最大的主体是北上广的漂流一族,而根本 不是本地人.

第二,从事弱智工作的男女主角2500块的月薪绝对不足以这样消费,购衣物,频繁在豪华饭店吃饭 ,和富二代群体地下赛车成为圈中人 ,甚至有那么大的朋友圈子.圈子很多还是建立在有钱有闲的基础上的.

第三,把两男女主人公的家的装修弄成时尚编辑的品味 非常可笑失真,尤其是工人家庭的男方家里那个 装修色彩,他阁楼单人间那几十个灯泡做成的装饰顶和他妈因为每月都是小区用水最少的一家而得了30元的节水奖形成鲜明反差,一个老中轻四口之家,常年在家做饭的,用水怎么可能比单身孤老,或者出差在外居多的单身人而少呢,这些都是属于为了表现一个人的抠门性格而生硬地造成的情节剧中还很多.

看看美剧,豪斯医生和BONES都是十大热门连续播了7,8年的电视剧,收视率在八百万到两千万 观众之间,裸婚江苏卫视首播是0.98%的最高的记录了.豪斯和BONES中宣扬的是美国现代最新的情感观,价值观,那就是 压抑的工作狂们企图用理性,科学,哲学,生理学来 淡化人的不期而至的因长期工作中相处而产生的强烈感情冲动 ,希望自己的人生建立在完全的理性而不是任由不可控的情感因素摆布.


在美国这样的最自由的国家,可以个人合法拥有枪支,自己自由迁徙,文化开放,精神自由的国家,电视剧中情感表达 的主流方式居然是压抑和理性,而中国这样一个全面 压抑,无论物质和精神上都倍受压制的国度,电视剧选择的都是白痴主人公和配角不加控制地无度宣泄.


电视里的老一代都是封建愚昧的代表,集中了中国人丑陋的一面,年轻一代却是好象生活在温室中的花朵一样,哪怕是贫二代贫三代们,都操着得瑟的北京 痞子富二代的腔调,明明是普通人家的女儿也要搞得一副公主模样,把80后独生子女演绎得太过分地娇气天真幼稚了,26,7岁的人比人家16,7岁还要小 白,真不知道是不是把模特演员中的80后的平均智商水平当做白领职场的80后精英智商水平了.

豪斯和BONES中的男女都是在压力巨大的精英职业下孤独的单身着,分分合合中,面对着他们人生的一个一个挑战 ,抉择,总是在理性思考着,艰难地忍耐着,而我们中国电视里的80后们,只会适应国情地搞点职场潜规则,从不好好工作,生活中的突破都来自于突然冒出个多年未见的富豪老爹,和公司一个潜伏着的富二代的小姐的不惜利诱威逼的倒追.

这其实多少反映着我们社会中绝望的贫二代对未来的美好想象仅限于被富二代们解救一下了,以致于编剧的想象力也局限在其中了,事实上有着不可调和的阶级仇恨和矛盾的穷二和富二在电视剧中由于性别的吸引力而美化成一家人了.


也许中国人真没什么电视剧可看了,现代剧被文化阉割后,象裸婚时代这么矫情,演员歇斯底里过分表演的电视剧也能被称为热门剧, 最为可笑的情节是一个用打掉三胞胎来换得富翁男友给的一本房产证,从此住上200平米豪华房子的女配角,居然被个去偏远省份小学义务支教的博士傻样男所感化,而把北京的用青春和屈辱,身体,血泪换来的房子卖掉的钱来捐助给山区小学,不知道这种精神鸦片是不是能让广大的贫二代80,90后而欣快,还是社会的精神救赎只能通过弱智电视的无限意淫来完成了.

美剧的理验就是聪明人,智商越高的人越感到孤独而痛苦,为了拉近和智商平庸的人之间的距离,只能吃药喝酒麻痹自己进入热闹的人群中产生亲近感,而中剧就是猪狗一样拥挤在一起的生活品质,成天无理取闹地内耗也叫大家庭的爱,眼泪汪汪地抱在一起就是大结局,却不能忍受有尊严的分手离别,从一而终永远是正确的.

理念的落伍与迂腐并不只是讨好电视剧机前的40,50观众,多少也误导太年轻的那个群体,非常失望,中国的电视剧真的太差了.

Add Comment
 
Kill Speed 07/22/2011
0 Comments
 
Picture
毋庸置疑我所喜欢的电影全部都是所谓的烂片。但是这另一部烂片的中主人公的生活方式实在是太吸引人了。仗着令人惊叹的驾驶技巧,开着自己的飞机,做一些偷鸡摸狗、受良心谴责、一不小心便暴尸天空的勾当,赚了大笔的钱后买幢豪宅。多么独特的事业,多么过瘾的人生!

由于出众的飞机驾驶技巧,和不怕死的亡命徒精神,主人公得以和最阴险狠毒的黑帮老大交涉。这种游侠的感觉真酷!黑帮老二及以下所有人等往往在森严的等级制度中经营挣扎,可是作为主人公这样的游侠,便可以只谈业务,而且收入丰厚。这是一种怎么样的事业高峰啊!

做人最难的,恐怕就是做一个真正普通,明白普通的乐趣的普通人了。

Add Comment
 
Do you feel bad when you have to learn new things? 07/02/2011
0 Comments
 
Picture
This is from a question I asked on stack-exchange:
http://programmers.stackexchange.com/questions/88703/do-you-feel-bad-when-you-have-to-learn-new-things

New thing is not always cool.

I see many people say they are very bored by doing the similar things day after day. For me it's the opposite - I'm always learning something new. During the last one and a harf year, nearly every two months I need to do lots of researches on a totally new topic: RTMP, MP4, SIP, VNC, Smooth streaming, ..., I have to read lots of specifications, download tones of open source projects to understand concepts, and turn them into my runnable code.

And it was so bad! My brain has never been very sure and very familiar with anything, and when it's close to be sure and familiar, it'll have to switch to next thing. I kind of envy people who build upper level applications because they can be very focusing, and their knowledge set includes most things their job requires. Everything is quite measurable, direct and straightforward.

Have you ever had the similar feeling? I'm thinking of asking my boss to assign me some other piece of work so that I work like moving forward on a broad road instead of figuring out a way in the dark, I think it'll be more relaxing, any suggestion?

The accepted answer:

It's about balance. Never learning anything new is ... unstimulating. That is terrible.

Equally, always having to rush to learn things, and never enjoying the thrill of mastering something, is exhausting.

As a developer you should never stop learning. And sometimes you'll have to learn slightly irrelevant things - legacy systems and the like. All that's okay, so long as you're not always poking around uncertainly in the dark.

The worst part about that is you're probably being treated as the 'expert', and you feel the pressure of knowing what you don't know.

I don't think that there's anything wrong with saying that you feel saturated as a 'jack of all trades' and would like to focus more on a particular area. Try to highlight the business benefits. If there aren't any - well, the business needs to focus a bit more.
Add Comment
 
<< Previous

    About tactoth

    Programming and other stuffs

    Archives

    March 2012
    February 2012
    January 2012
    December 2011
    October 2011
    August 2011
    July 2011
    June 2011
    May 2011
    April 2011
    March 2011
    February 2011
    January 2011
    December 2010
    September 2010
    August 2010
    July 2010
    June 2010
    May 2010
    April 2010
    March 2010
    February 2010
    July 2009
    April 2009
    November 2007
    December 2006
    November 2006
    May 2006
    June 2005

    RSS Feed

    Links
    Song's Happy English

Create a free website with Weebly