Pages

Showing posts with label Lazarus. Show all posts
Showing posts with label Lazarus. Show all posts

Saturday, April 20, 2024

낯선 Rust에서 오래된 Object Pascal의 향기를 느끼다

요즘 새로운 프로그램을 만드는데, 이 참에 공부좀 해보자 해서 Rust로 만들어보고 있습니다.

아무래도 멘땅에 헤딩하다 보니까 고조할아버지 제삿날 종가집 시어머니급 잔소리를 늘어놓으며 사사건건 시시콜콜하게 간섭해대는 rust-analyzer와 싸우면서(?) 즐거운(?) 나날을 지내고 있습니다만...... 오늘 재미있는걸 하나 발견했습니다.

Rust에서는 이 구문을 오류로 보더군요.

이걸 수정하려면 이렇게 고쳐야 됩니다.

이 코드를 보니 예전 Object Pascal (Delphi) 시절이 생각나는군요. primitive type이 아니면 var 절에서 객체 변수를 선언한 뒤에 구현부에서 꼭 초기화를 시켜줘야 하고, 그렇지 않으면 바로 runtime error를 뻥뻥 토해냈는데, 구조가 완전히 똑같습니다. Rust도 마찬가지이긴 합니다만, 차이점이라면 메모리가 할당되지 않았다는걸 컴파일 타임에 발견해낼 수 있다는 정도일까요.

Pascal이란 언어는 자기 자신은 비주류인 주제에 온갖 잡다한(?) 언어들에게 무수한 영향을 끼치는군요. Java도 Python도 Javascript도 심지어는 Rust도 모두 다 Object Pascal의 구조를 일정수준 이상 차용해왔으니......

과거 해당 언어의 추종자로서, 아련한 기분이 듭니다.

See old Object Pascal from new Rust

Nowadays I'm working on a new application, and I thought it's a good chance to learn something new, I tried Rust.

As a newbie(or noob) in this area, I enjoy the time fighting against rust-analyzer that always-whining like Grouchy Smurf...... (lol) And today I found something interesting.

In Rust, the following is an error.

To fix, the first line should be changed like following.

Seeing the code reminds me of the good old days of Object Pascal (Delphi). If it's not an primitive type you've got to declare the variable in var clause and call constructor in implementation, or it'll emit runtime error. And Rust "inherited" the structure as it was, except for catching non-memory-assignment in compile time.

The programming language Pascal is a minor one as it is, it influences to too many other languages, like Java, Python, Javascript, and now Rust....... They all adopted at least some part of Object Pascal.

As a good follower of the language, I feel dim as I saw this.


Tuesday, August 12, 2014

Lazarus+Firebird+ZeosDBO: Cannot read files in Hangul

When connecting to Firebird using ZeosDBO in Lazarus, if the filename contains Hangul(Korean), the database file cannot be read. Using UTF8ToSys() or Utf8ToAnsi() was of no use. The error occurs when Firebird calls CreateFile(open), though with TIBConnection the file can be read if I apply UTF8ToSys() to DatabaseName.

I liked ZeosDBO as it seems faster that TSQLConection, but now is the time to turn off autocommit and manually do it. Well, considering the origin(a component for Delphi), support for Lazarus is ought to be limited.

Found in following environment:
Lazarus 1.2.4, ZeosDBO 7.1.3a, Firebird 2.5

P.S:Considering the case, the same would happen to files with Chinese or Japanese characters in the name. Pity to CJK users!(including me)

Lazarus+Firebird+ZeosDBO: 한글 파일명 읽기 불가능

Lazarus에서 ZeosDBO를 사용해서 Firebird에 접속할때 파일명이 한글로 되어있으면 파일을 읽지 못하는 문제가 있습니다. UTF8ToSys()나 UTF8ToAnsi()를 사용해도 마찬가지였습니다. 정확히는 Firebird가 파일을 읽기 위해 CreateFile(open)을 호출할때 오류를 일으킵니다. 하지만 TIBConnection은 DatabaseName에 UTF8ToSys()를 적용해주면 정상적으로 동작하더군요.

ZeosDBO가 TSQLConnection보다 속도가 빨라서 좋아했는데, 이젠 TIBConnection에서 autocommit 끄고 돌린 다음에 수동으로 commit하는게 나을 것 같습니다. 아무래도 델파이용으로 만들어진 컴포넌트다보니 Lazarus 지원은 썩 좋지 않은 듯 하네요.

Lazarus 1.2.4, ZeosDBO 7.1.3a, Firebird 2.5에서 확인했습니다.

Thursday, March 13, 2014

라자루스로 돌아오다

6개월인가, 8개월인가정도만에 라자루스를 다시 설치했습니다. Qt가 거의 모든 기능을 제공해줄 뿐 아니라, Boost와 함께 쓰면 더이상의 것은 필요없다는 말이 나올 정도로 완벽했지만, 아무래도 덩치가 너무 큰게 마음에 걸리더군요. 예. Qt의 단점을 논할때마다 꼭 나오는 말이지만, 기능이 너무 많아서 라이브러리가 무식하게 커지는 단점이 꼭 켕겼습니다.

최근에 Qt를 가지고 간단한 GUI 프로그램을 만들 일이 있었습니다. 별건 아니고 libssh를 사용해서 SCP로 다운로드받은 내용을 Qt Quick Control에 있는 테이블로 보여주는 프로그램이었는데, 이게 이것저것 다 합치니 50MB정도가 되더군요. 뭐, 반정도는 ICU(27.5MB)였으니, ICU를 빼고 Qt를 다시 빌드하면 크기가 좀 줄어들긴 하지만 EXE, DLL, 그리고 Qt Quick Control을 구성하는 QML 파일들을 모두 합치면 이것도 여간 번거로운게 아니죠.

가장 큰 문제가 되는 부분은 프로그램의 cold start가 일어날 때입니다 - 제 Core i5에서도 프로그램이 인터페이스를 띄우는데게 3초가 넘게 걸렸습니다. 이정도 시간이면, 사용자가 “왜 프로그램이 실행이 안되냐” 하면서 프로그램 아이콘을 다시 클릭하고도 남을 시간입니다.

하여간 이래저래 켕기는게 있어서 대안을 좀 찾았습니다. 그리고 그 물망에 오른건 wxWidgets와 Lazarus였습니다. 사실 첫번째 후보는 wxWidgets였습니다 - 어쨌든 C++ 사용자는 Object Pascal 사용자보다 많은게 현실이니, 도움은 더 받을 수 있으리라는 생각이 들더군요(뭐, 제가 따로 조사해본 결과를 통해 추측해보면 wx 사용자나 Lazarus 사용자나 수는 대충 비슷해 보이긴 합니다만……).

승부는 빈 창을 띄우는 프로그램을 빌드한 이후 갈렸습니다. wxWidgets는 7.45MB짜리 프로그램을 만들어냈고, (개인적으로 심한 애증관계에 있는)Lazarus는 1.44MB짜리 파일을 만들었습니다. 둘다 cross-platform이고, native widget을 사용하는 동일 구조라는걸 고려해본다면, 승자는 Lazarus더군요.(참고로, Qt는 native widget을 사용하지 않습니다. 단지 인터페이스를 native처럼 그려내기 위해 관련 DLL을 참고할 뿐입니다.)

하지만, 그럼에도 불구하고, 그놈의 적은 사용자 수가 끝까지 제 발목을 잡았습니다. 주변에 물어볼 사람도 없이 혼자서 맨땅에 헤딩하는 상황이 될게 뻔했던거죠.

그런데 이 때, 제 친구 중 한 분이 중요한 한마디를 하더군요:
“좋아하는 걸로 하세요.”
삽질을 각오할 열정이 있다면(……), 사용자 수가 적은건 별로 문제가 되지 않습니다. 사실 모든 사람들이 아무 생각 없이 몽땅 다 주류만 쫓아갔다면, D나, Vala나, Haskell같은건 있지도 않았을거고, LISP같은 것들은 아마 살아남지 못했을 겁니다.

결국 이놈의 애증 만발한 라자루스가 다시 제 시스템에 설치되었습니다. 이걸로 뭘 더 하게 될지는 모르겠지만, 어쨌든 언젠가는 뭔가 하게 되겠죠.

추신:
Lazarus를 떠나있는 동안 instantFPC라는게 나왔더군요. 이게 뭔가 하니 파스칼 소스코드를 스크립트처럼 쓰는건데…… 사실은 실시간으로 후딱 컴파일하고 돌리는 거랍니다. 뭐 파스칼 컴파일러가 무식하게 빠른거야 어제오늘 일이 아니라는걸 보면, 이렇게 무식한 구조로 JIT(..??) 컴파일러를 만들어도 크게 문제는 없을 것 같긴 합니다.
(제 Core i5 시스템에서 Lazarus IDE를 -O3로 처음부터 다시 컴파일하는데 2분이 채 안 걸렸습니다.)

Back to Lazarus


I reinstalled Lazarus. It’s been a while - about 6 to 8 months or so. Using Qt, though the library provided almost everything, especially when used with Boost, I was always concerned with the fact that it’s too heavyweight - yes. Qt is feature bloated and the size of library is sometimes too big.

Recently I developed a simple GUI application, which downloads something using SCP and show on a grid. It was based on Qt Quick Controls and libssh. Later I found out that the package was bigger than 50MB. Of course half of the library was ICU(about 27.5MB) so I could remove it if I rebuild Qt without ICU, but still it’s 25MB with lots of files(EXE, DLL, as well as a lot of Qt Quick Controls QML files). The size of file matters, especially in cold start - in my Core i5 system, the application needed more than 3 seconds to show its main interface. It’s slow enough for the user to click the icon again, thinking that Windows in some way ignored user’s click.

So I searched for some alternatives. I considered two: wxWidgets and Lazarus. My first consideration was wxWidgets - well, anyway there are far more C++ users than Object Pascal users so I may get more helpful materials(though according to my short research on a few sites, actual user base would be about the same for both).


The winner was clearly Lazarus. Both are cross-platform, and use native widgets, meaning smaller application = simpler architecture = faster speed. After building a GUI application with empty form, I turned to my beloved love-hate Lazarus again - wxWidgets gave me an EXE of 7.45MB, while Lazarus gave me one of only 1.44MB.
(c.f. Qt is not native - it just ‘refers to’ native GUI library to draw the interface in native way.)

But I was still reluctant to use Lazarus again, because I clearly know how small the user base of Object Pascal is, meaning I may be the lone survivor after all other developers turning back to other environment, fighting the hard fight.

And this time, one of my friend said something important:
“Do whatever you’d like to do.”
Small user base is not a problem so long as you have passion. If everyone mindlessly follows the mainstream, there would be no D, Vala, Haskell, etc., and LISP and others would not have survived.

So I landed again to the land of my beloved love-hate Lazarus. I’m not sure what I’ll do with this thing, but I’m sure that some day I’ll do something with it.

P.S:
During the time I left my FreePascal/Lazarus world, the Lazarus team made something fun; instantFPC. It reads FPC source code and run it as if it’s a script. In fact it compiles the source code and run the binary, but please remember, Pascal compilers are among the fastest compilers in the world(in my Core i5 system it took less than 2 minutes to fully rebuild Lazarus IDE with -O3 switch).