I moved a 4000 line coffeescript project to typescript and I liked it

TLDR: jump straight to the TypeScript section
About 8 months ago I started a new complex web app in javascript, and it quickly grew out of hand.
It had:
  • a server with routes
  • a singleton object with state, logic and helper functions
  • a bunch of similar plugins that extend functionality
  • the singleton object lives both on the server and on the client
Very soon I decided that javascript allowed too much patterns. I wanted modules, classes and easy binding on the this keyword.
Someone recommended CoffeeScript and I went with it.
The codebase expanded to about 4000 LOC in a matter of weeks.


So CoffeeScript hm, what about it?

These are my experiences after maintaining a non-trivial coffeescript application for a couple of months.

Pros:
  • Programming was quicker, stuff you want is already in the language. (classes, inheritance, array comprehension, filters)
  • Less verbose.
  • for k,v in object
  • fat arrow
  • "string interpolation #{yes.please}"
Cons:
  • fat arrow is very similar to thin arrow, git diff thinks this sucks
  • syntax. The attempt of avoiding braces is horrible. Function calling is a mess.
  • It smells like ruby. I dislike ruby with a vengeance.
  • no more var keyword? This is disturbing and error prone, given its significant subtleties in javascript.
  • everything is an expression? I like to be explicit about return values kthnxbye.
The result: a buggy codebase that feels scary, lots of unsafe monkey patching, coffeescript that seems to disagree with the idea of coffeescript.


TypeScript

When I started this codebase TypeScript had just launched. I deemed it a bit too experimental to work with, but last weekend I decided to give it a go. On Sunday I did git checkout -b typescript-conversion, installed the typescript syntastic plugins and started up vim. Fourteen straight hours of refactoring later it was done and 4238 lines of coffeescript had turned into 6145 lines of typescript.

I compiled all the .coffee files to .js files, removed all the .coffee files from the repo, and renamed all the .js files to .ts. Technically I was already done, as js is a strict subset of typescript, but doing everything typescript style was a bit more work.

Here are my experiences.

Pros:
  • fat arrow: removed almost all uses of self = this.
  • static type and function signature checking. I immedeately fixed about ten hidden bugs thanks to this.
  • classes and modules have never been easier
  • linking using tags
  • compiling linked files to one concatenated file out of the box using tsc --out
  • aim at ecmascript 6 forwards compatibility
Cons:
  • slower tooling (vim syntastic takes about 3-5 seconds after each buffer save)
  • no way of doing stuff like for k, v in object
  • no string interpolation
  • no automatic ecmascript 3 compatibility layer (monkeypatching Array with indexOf etc.)

Conclusion


I really really really like TypeScript. My project feels really clean, I see lots of room for improvement (and this time I know where to start). For larger codebases typescript will greatly improve maintainability.

If you work on a large codebase you can either automate testing, enforce developer discipline or move to static typing and a compile step. I think the last option is greatly preferred.

Comments

  1. fjärr övervakning

    Vi erbjuder Kvalité och snabb service och vet att det är mycket viktigt att få saker gjort snabbt , därför kan vi erbjuda service avtal Från 99:-/mån så du får snabbt på plats service (även distans avtal)och så ser vi till att du alltid håller ditt kassasystem uppdaterad med den nyaste programvaran!

    Kontakt información:

    Norra Ågatan 5 A Arboga Västmanland 732 31
    teléfono: 0589-10031
    Site: www.kassanetto.se

    ReplyDelete
  2. đồng tâm
    game mu
    cho thuê nhà trọ
    cho thuê phòng trọ
    nhac san cuc manh
    số điện thoại tư vấn pháp luật miễn phí
    văn phòng luật
    tổng đài tư vấn pháp luật
    dịch vụ thành lập công ty trọn gói
    lý thuyết trò chơi
    đức phật và nàng
    hồ sơ mật dinh độc lập
    đừng hoang tưởng về biển lớn
    chiến thắng trò chơi cuộc sống
    lượng tử
    ngồi khóc trên cây
    truy tìm ký ức
    mặt dày tâm đen
    thế giới như tôi thấy

    Tâm Tố Nương bấm loạn tựa như nai con, muốn giãy dụa đứng lên nhưng lại bị một đôi cánh tay mạnh mẽ ôm chặt chiếc eo nhỏ bé, làm nàng không thể nào động đậy.
    Mềm mại nằm trong lồng ngực nam nhân, khuôn mặt nóng bừng ép chặt vào lồng ngực ấm áp của Lưu Phong làm cho thân thể của Tố Nương cảm thấy như bốc cháy.
    Lưu Phong ôm vưu vật là nữ nhân thành thục vào trong lòng. Ngửi thấy hương thơm nhàn nhạt trên người nàng, hơi thở dần dần gấp gáp, càng ôm nàng chặt hơn, bổng bổng phía dưới đã dính chặt trên tiểu phúc của nàng, thật là nóng bỏng.
    Mặc dù mỗi đêm đều chờ mong, nhưng chính thức sắp tới lúc đó Tố Nương càng thêm khẩn trương, dán chặt cả người lên người hắn, đến thở mạnh cũng không dám, đôi song nhũ đầy đặn đè lên ngực Lưu Phong, mang đến cho hắn khoái cảm thấy khác thường, Lưu Phong thoải mái kêu lên 1 tiếng, hai tay theo tiết tấu nhẹ nhàng xoa bóp phong đồn tiêu hồn của nữ nhân.
    “ Thiếu gia ………. như vậy là không tốt.” Tố Nương có chút khẩn trương: “Vạn nhất để phu nhân trông thấy thì thật không tốt…” dù sao Lưu Phong bây giờ đã có thê tử, Tố Nương trong lòng cũng có chút e dè.
    Lưu Phong cười hắc hắc, nói: “Tố Nương tỷ tỷ, người yên tâm, Tố Tố biết chuyện của chúng ta, nàng sẽ không tức giận đâu.” Kỳ thật lời nói của Lưu Phong lúc này có chút giả dối, Ân Tố Tố cũng không biết hắn và Tố Nương có quan hệ với nhau. Đương nhiên Lưu Phong nói dối lúc này có phần thiện ý làm giảm bớt áp lực cho Tố nương lúc này.
    Quả nhiên nghe xong, mơ màng kêu nhẹ một tiếng, trong mắt như có một tầng hơi nước, trên mặt ửng hồng một mảng, cố ý đung đưa thân thể, dùng bộ ngực sung mãn áp lên thân thể Lưu Phong.
    Lưu Phong nhẹ nhàng xoa bóp cặp mông mềm mại, sau đó chậm rãi cởi bỏ chiếc váy, rồi cầm lấy bổng bổng chầm chậm tách hai chân nàng ra, cọ cọ vào đám cỏ thơm ngát trên dải đất bằng phẳng của nàng.

    ReplyDelete

Post a Comment

Popular posts from this blog

The unreasonable effectiveness of i3, or: ten years of a boring desktop environment

Idea time: RFID+E-Ink, electronic price tags without batteries

Parsing 10TB of Metadata, 26M Domain Names and 1.4M SSL Certs for $10 on AWS