Languages of the Year 2009
It's almost the end of the year 2009. This year is special because I've never dealt with so many languages in a year. Objective C, Python, Java, C++, PHP, JavaScript, Haskell, Prolog, Ruby, C#, and probably more. Some of them were for work, some for school, and others were for my personal projects. I have plenty of stories for each language, but I'll try to keep them brief.
Objective C
CQube iPhone edition was released back in March, and as you know Objective C is the language you use for iPhone application development. Objective C is a strict superset of C, so it didn't take too much effort to learn. Rather, I spent most of time to learn the Cocoa framework. All those magic keywords like @property, @synthesize, and @dynamic were nice to have.
Python
I love Python. I used Python for many different things; from disposable command line utilities to implementation of Apple Push Notification service. I also used this language to conduct a classified operation. After I learned Haskell, which is what I'm going to talk about in a minute, I started enjoying use of higher order functions such as map, reduce, filter, and so on.
Java
I also use Java a lot. I built a Java mobile application at my work. I also built a nearest neighbor search engine, an HTTP based real time communication framework, and a Luca compiler. There are probably more, but these are the ones I remember. There are few things that I really wish to have in Java: automatic getter/setter, operator overriding, and delegate. Could someone give me these as a Christmas gift? ;-)
C++
To be honest with you, I'm kind of scared of this magic language. I would say it's quite difficult and takes a considerable amount of practice to use this language properly and effectively. Well, in my compiler class, I had to use either C or C++ to implement a Luca interpreter with indirect threading.
PHP
I'm not a big fan of this language. Ironically, this is probably one of the top three languages that I spent most time with so far. I had a web application development job over the summer. It was a lot of PHP programming. I also had to build server side components at my current work. I wanted to use Python, but apparently not many people know Python. So, I had stick with whatever language that most people can deal with.
JavaScript
You would imagine using JavaScript to manipulate the DOM structure of a web page. But, this is not the only case. I used this language to build a Firefox extension (thanks to Justin Samuel's Firefox extension development tutorial). I can't tell you what it is though because it's a part of a classified operation.
Haskell
Haskell changed a lot of things in my point of view of programming. All the functional programming features and its imperativeness really blew my mind. Basically it made me a better developer in general. Even though I have no intention to use Haskell in production environment, I will be using things I learned from this language.
Prolog
Cody Jorgensen:
Why can't I get an element from the god damn list?
Ruby
It was very joyful to learn Ruby as I already know how to use Python. Ruby is very similar to Python in many different aspects as C# is similar to Java. I see blocks and the yield keyword as a giant lambda function, and I kind of like it. One thing I like from this language over Python is that there's end keyword so that you don't have to be super careful about indentation. Because of this, there's no need to make a new template language in web application framework such as Ruby on Rails, whereas it is necessary in Python based frameworks such as Django. Oh, it's also very nice to have built-in regular expression features.
C#
We decided to switch from Nokia's Symbian to Microsoft Windows Mobile platform at my work. I was hoping the Java code I've been writing works just fine on the Windows Mobile, but few things didn't really work out well. So, I decided to re-write the whole application in C#, and I did it over the last weekend. I wouldn't be able to make all these happen without Visual Studio's great help. Not to mention I didn't have to re-write all the server side components.
염장 타이머
오랜만의 한국어 포스팅입니다.
오늘은 혼자이신 분들을 가슴아프게 하는 타이머를 하나 공개해볼까 합니다. 만든지도 거의 1년이 다 되어가네요. 아래의 스크린샷을 클릭하면 실제 작동되는 타이머를 볼 수 있습니다.
jQuery 는 여기서 구할 수 있습니다. 사실 아래의 코드를 구동하는데 jQuery 가 꼭 필요한 것은 아닙니다. 그냥 평소에 쓰던게 편해서 쓴것일 뿐. document.getElementByName(), element.innerHTML 정도만 직접 작성해주면 jQuery 없이도 구현할 수 있습니다.
new Date('Feb 14, 2008 21:31:47');
이 부분을 특별한 날(?)의 날짜와 시간을 집어넣으면, 그 시간부터 지금까지 얼마나 지났는지 보여주는 간단한 타이머입니다. 저야 여자친구와 사귀기 시작한 날을 집어넣었습니다만, 사실 꼭 그럴 필요는 없겠지요. 미래의 날짜를 넣어도 되는데, 이 경우엔 카운트다운이 됩니다.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<title>xenia.sumin.us</title>
<style type="text/css">
div#content {
position: absolute;
top: 50%;
width: 98%;
margin-top: -25pt;
font-family: sans-serif;
font-size: 50pt;
font-weight: bold;
text-align: center;
}
</style>
<script type="text/javascript" src="jquery-1.2.6.js"></script>
<script type="text/javascript">
var offset = new Date('Feb 14, 2008 21:31:47');
var curr = new Date();
var diff = parseInt((curr.getTime() - offset.getTime()) / 1000);
function update() {
var time = diff < 0 ? -diff : diff;
var sec = time % 60;
time = parseInt(time / 60);
var min = time % 60;
time = parseInt(time / 60);
var hours = time % 24;
time = parseInt(time / 24);
var days = time;
if(sec < 10) sec = '0'+sec;
if(min < 10) min = '0'+min;
if(hours < 10) hours = '0'+hours;
$('#content').text(days+' days '+hours+':'+min+':'+sec);
diff++;
}
setInterval(update, 1000);
</script>
</head>
<body onload="update()">
<div id="content"></div>
</body>
</html>
‘너 어느 별에서 왔니’의 소스코드 분석
http://heygom.com/blogthings/planet/
index.html, result.php 파일 두개로 이루어져있다. result.php는 $GET[planet] 값에 따라서 적절한 페이지를 출력해주는 일을 하고, 출신 행성--?은 index.html에서 submit을 하기 전에 자바스크립트 process() 함수에 의해서 미리 정해진다.
process() 함수의 내부는 크게 4부분으로 나누어져있다. 1. 변수 선언부 2. 사용자의 입력값을 종합하는 부분 3. 정렬하는 부분 4. 현재 페이지의 location.href 값을 바꾸는 부분(결과 페이지로 이동)
총 문항 수는 6개, 문항당 보기의 수는 10개이다. 각 보기는 차례대로 sun, moon, mercury, venus, mars, jupiter, saturn, uranus, neptune, pluto 에 대응된다. 예를 들면, 사용자가 첫 문항에서 두번째 보기를 선택하면 moon 의 값을 1 증가시키는 방식이다.
이렇게 종합된 값을 가지고 정렬을 하는데, 맙소사[!] 정렬 방식이 매우... (좋게 표현해서) 비효율적이다. 반복문 쓰면 3~4줄이면 될것을 if문을 10개 써서 구현해놨다.
이 프로그램의 논리적 오류: 1. 행성 변수(sum, moon 등..)의 값이 같으면 위에 서술한 순서대로(sun, moon, mercury...) 높은 우선순위를 가지게 된다.
개선할 점: 1. 기존의 구조를 그대로 유지할 경우 1) 체크된 변수를 찾는 부분 break문을 써주면 약간의 성능향상 및 시스템 자원 절약 효과를 기대할 수 있음. (그렇다고 인간이 느낄 수 있는 차이는 아니다;ㅋㅋ) 2) 행성 변수의 값을 증가시키는 부분 if문 10번 대신 switch문을 쓰는것을 추천.. 3) 정렬 만든 사람의 노가다에 경의를 표하며-_-; for문을 쓸 것을 권장함. 2. 새로 만들 경우 one.value 를 쓰면 반복문 쓸 필요도 없는데.. one[i].checked 로 모든 값을 검사하는건 다중 선택이 허용될때나 그렇게 하는것이다. 배열을 적절히 사용한다면 위의 2, 3번 과정은 만들 필요도 없다.
소스코드 보기가 너무 불편해서 내가 들여쓰기 스타일을 좀 바꿨다.
function process()
{
var sun = 0;
var moon = 0;
var mercury = 0;
var venus = 0;
var mars = 0;
var jupiter = 0;
var saturn = 0;
var uranus = 0;
var neptune = 0;
var pluto = 0;
var f = document.f;
var i = 0;
for (i = 0; i < f.one.length; i++)
if (f.one[i].checked)
value = f.one[i].value;
if (value == "1") { sun++; }
if (value == "2") { moon++; }
if (value == "3") { mercury++; }
if (value == "4") { venus++; }
if (value == "5") { mars++; }
if (value == "6") { jupiter++; }
if (value == "7") { saturn++; }
if (value == "8") { uranus++; }
if (value == "9") { neptune++; }
if (value == "10") { pluto++; }
for (i = 0; i < f.two.length; i++)
if (f.two[i].checked)
value = f.two[i].value;
if (value == "1") { sun++; }
if (value == "2") { moon++; }
if (value == "3") { mercury++; }
if (value == "4") { venus++; }
if (value == "5") { mars++; }
if (value == "6") { jupiter++; }
if (value == "7") { saturn++; }
if (value == "8") { uranus++; }
if (value == "9") { neptune++; }
if (value == "10") { pluto++; }
for (i = 0; i < f.three.length; i++)
if (f.three[i].checked)
value = f.three[i].value;
if (value == "1") { sun++; }
if (value == "2") { moon++; }
if (value == "3") { mercury++; }
if (value == "4") { venus++; }
if (value == "5") { mars++; }
if (value == "6") { jupiter++; }
if (value == "7") { saturn++; }
if (value == "8") { uranus++; }
if (value == "9") { neptune++; }
if (value == "10") { pluto++; }
for (i = 0; i < f.four.length; i++)
if (f.four[i].checked)
value = f.four[i].value;
if (value == "1") { sun++; }
if (value == "2") { moon++; }
if (value == "3") { mercury++; }
if (value == "4") { venus++; }
if (value == "5") { mars++; }
if (value == "6") { jupiter++; }
if (value == "7") { saturn++; }
if (value == "8") { uranus++; }
if (value == "9") { neptune++; }
if (value == "10") { pluto++; }
for (i = 0; i < f.five.length; i++)
if (f.five[i].checked)
value = f.five[i].value;
if (value == "1") { sun++; }
if (value == "2") { moon++; }
if (value == "3") { mercury++; }
if (value == "4") { venus++; }
if (value == "5") { mars++; }
if (value == "6") { jupiter++; }
if (value == "7") { saturn++; }
if (value == "8") { uranus++; }
if (value == "9") { neptune++; }
if (value == "10") { pluto++; }
for (i = 0; i < f.six.length; i++)
if (f.six[i].checked)
value = f.six[i].value;
if (value == "1") { sun++; }
if (value == "2") { moon++; }
if (value == "3") { mercury++; }
if (value == "4") { venus++; }
if (value == "5") { mars++; }
if (value == "6") { jupiter++; }
if (value == "7") { saturn++; }
if (value == "8") { uranus++; }
if (value == "9") { neptune++; }
if (value == "10") { pluto++; }
var out = "sun";
i = sun;
if (moon > i) {
out = "moon";
i = moon;
}
if (mercury > i) {
out = "mercury";
i = mercury;
}
if (venus > i) {
out = "venus";
i = venus;
}
if (mars > i) {
out = "mars";
i = mars;
}
if (jupiter > i) {
out = "jupiter";
i = jupiter;
}
if (saturn > i) {
out = "saturn";
i = saturn;
}
if (uranus > i) {
out = "uranus";
i = uranus;
}
if (neptune > i) {
out = "neptune";
i = neptune;
}
if (pluto > i) {
out = "neptune";
i = neptune;
}
location.href = "./result.php?planet=" + out;
}
