Tag Archives: Programming

Weight your toys

After sleeping for nearly 12 hours, another sleepless night passed. I decide to write this post because this post reminds something about my weakness when dealing with algorithm problems. Maybe my low IQ is which I should blame to. But I love my parents, this is not their fault. So I think I should try to confront the shadow side. At least I have plenty of time to prove how poor my mind is, and before that I shall not give up my weakness.

Enough for dirty words. Here’s the problem, I put it to the gist.


 

How to abstract reality problems to sort problems, and how to take advantage of sort to find out things that interest us?

The code above, I want to use observer design pattern ( compare_event ). Yes that’s the part to emphasise that we always want to search things interest us, if not, why we search things? So that is the pattern of human beings, and I always decouple things when I find a point that fit normal brains.

Here is the steps that I always follow to create a solution:

  1. Understand them, feel them, and try to measure them. We always have a way to quantify things, though most people die here or find a really bad way to measure things.
  2. So we have convert states to numbers in the first step. We can use the numbers to compare two things.
  3. If I want to search something, I always search things while sort them. You always do the two things together, think about it when you are paring the socks from your washing machine. Even school child does it without thinking.
  4. I interpolate tasks while each comparison. Searching itself is also a task. Each task can access the current comparison result and process state.
  5. Choose a sort algorithm which fit the situation best
  6. Launch the whole process.

 

Why my naming convention thought is different

I heard a lot of voices saying that they want to make their coding style the same with the corresponding frameworks, so they study the ancestors’ codes and mimic the so called golden standards.

Keeping coding style the same with the framework is no wrong. But don’t lost your own voice when you are trying to follow other’s. 

I prefer my coding style being different from the framework that I’m using. One big advantage is that it will be much easier to distinguish which part of the codes is mine and which belongs to the API. For example, a mix of camelCase and underscore conventions:

If a new member comes to read this java snippet, he will find it useful to find the road map of this project. Sometimes I think a proper way to mix will make life easier, isn’t it?

Collective Phenomena

Inspired by this post, I wrote a CoffeeScript implementation. This is a very interesting phenomena that revealed the beautiful philosophy behinds the nature, a slight push to the collection of simplicity can make miracles : D

As you can see, each particle is just moving around on a circle orbit with the same velocity, only the initial position is different. However, when they are made a whole, things begin to be interesting.

Continue reading

My terminal theme

This theme is build on the top of zsh and the famous OH MY ZSHELL. Besides, it has been included in the official OH MY ZSH repo : D

To a compatible theme, I think it’s better not to use special characters like ╭  ➜  ✗ . If you want your theme works fine on both Unix and Windows, a clean format and a simple color scheme are necessary. Therefore, I use only ANSI Character Set and ANSI Colors. The main goal of this theme is to make the  *nix servers’ admins happy. This theme is even more robust than the default theme robbyrussell.

I separate each command group with an empty line in front of the “#” prompt. The indicator words are all in a dim color. The most eye-catching color yellow is assigned to the current directory. For other colors’ setting, the same color will be assigned to different location with a long distance. And the more important it is, the more warmer color it is assigned to.

For the purpose of making the beginner to learn the command line easier, I set the dollar symbol “$” as the main command prompt. The %” or “# indicates the current state of the terminal. The “L” indicates current shell level, it can be useful when you are in nested shells. The last “N” indicates the current command number, with the time stamp you it may help you calculate how long a command takes.

The basic theme format:

Continue reading

Some thoughts on the software’s auto-update design pattern

There are so many ways to get the program to have the ability of auto-update. But as I’ve known, there is no way can absolutely make sure the program will update itself as expected. For example, you have defined some data type, in your program and store the data locally. And you have happily distributed your product to thousands users. Then months pass, you add some details to the basic data type. You migrate all the user data properly, and everything gone fine. Not a single complain heard from you users. Things turned complicate when the third time you update your data type. Now you have 3 types of data. Some of your users may be still the oldest version. Fortunately, you have left a tag in the data type to mark the version of the data type. So you take your time to check the version, and implement 2 method to migrate the data.

How about if this pattern continues for around 10 times? How many migration methods you should implement? Nine, of course. But if for some reason some of your users have reversed the version to an old one? From the basic principles of combination, we need 10×9 which means 90 methods to meet the requirement. That sounds crazy.

The main problem is because you can’t be sure whether all the users have always updated to the newest version. In other words, you need to find a solution to sync all the users program version and don’t hurt their data. On one can predict the future, we never know how the data finally like.

To be continued…

统一的开发体验

目前来说网络应用是演变速度最快的应用之一。程序员们都习惯了用各种语言和工具混合拼凑自己的作品。比如一个人承担整个项目,开始做应用原型决定使用最快的方法完成草稿,于是选用IIS、.NET、C#、MVC、MSSQL完成主要草图,人性化的IDE加上完善的框架和Razor渲染引擎,这个过程在没有任何阻碍的情况下完成。然后由于环境的限制,下一步选用Apache、PHP、MySQL重构项目,虽说是重构,其实就是将把语言翻译下,整体思想不变,前端部分是scss、blueprint、 jquery、php等一些琐碎的东西,ajax接口部分可能要测试下大小写兼容,其他就没什么好修改了。当然这只是一个开始,部署项目、配置服务器,SEO优化,各种测试,这些都需要用到各种不同的知识,最后不要忘了前端设计知识更涉及各种更抽象的知识。

Continue reading

我们和代码的距离

我们总希望受控对象能尽可能的自理,但又能让任何一个细节完全受控于我们。我们讨厌琐碎的细节,希望不关心的都会有个默认值在那里等着我们。但是默认值总会有不适用的时候,我们总是无法用统一的方法解决问题,重构于是成为家常便饭。

我们要控制的对象总是不够聪明。

大一的时C语言考核有一项是:用字符模拟一个余弦波平行移动的动画,并且能通过光标控制波长和幅度。这是我的第一个界面程序。虽然是控制台模拟界面,没有抗锯齿,没有色彩,没有缓动,但是它让我发现了很多有趣的现象。比如开始编写时,我觉得为了调试平移动画就在右上角加入了显示平移计数,本来打算调试通过就注释掉,但没想到这个功能意外的可以便捷的扩展到幅度的调试环节,然后测试时又发现用光标控制波长和幅度时如果能显示数值的反馈会让操控更富有乐趣。于是这个一开始仅用于调试的功能不知不觉间变成了程序的一部分。

你有没有想过游戏的生命值显示一开始只是用于debug呢?开发者是否在开发过程中发现了乐趣呢?那些不认真编写单元测试的人是否无意间错过了无数美丽风景呢? Continue reading