Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6627203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:59:08+00:00 2026-05-25T21:59:08+00:00

I’m reading about CoffeeScript and am still trying to position the language, what can

  • 0

I’m reading about CoffeeScript and am still trying to position the language, what can be done, what are the best practices, etc; I’m more used to strongly typed languages (AS3, Java, Scala) so my two questions may make you smile a bit 🙂

Question 1: Custom collections

What do you think about custom collections ? JS/CS is one of the weakest languages in this aspect; For instance there is no Array.remove and you have to use the cumbersome splice() method instead. Some function libraries (Like underscore) augment the API by providing functions taking arrays/objects as the first arg but given the choice I would prefer to write:

list fancyFunction 3, 4

rather than

fancyFunction list 3, 4

Let’s say I create a List class; Is it possible and if yes, what are the requisites for this class to be able to use CS’s comprehension syntax ? Worst case scenario, I guess the List could have a toArray() method and the usual CS operations could be performed on that returned value instead, but I hope there is a better solution.

Ideally, I would like to be able to define rich, custom collections, but not at the cost of losing comprehensions, etc.

Question 2: Mutability

What are people feelings about being very careful with mutability in CS/JS in general ?

When I read various code online, I have the impression everything is mutable and people generally think it’s better not to bother and have less lines of code instead.

For instance, mutable versus immutable basic Point class: (Hopefully I’m not doing something wrong)

Mutable

class Point
  constructor: (@x, @y) ->

Immutable

class Point
  constructor: (x, y) ->
    @x = -> x
    @y = -> y

Not that much more complicated but slightly weirder syntax. Another consideration is that JS is not the fastest thing known to man and having to create lots of objects in a loop just for the sake of being a purist might be counter productive, performance wise. I didn’t benchmark the cost of creating new Point objects versus altering the members of one though.

Imagine a big app with lots of modules communicating through thin APIs. Wouldn’t you want to pass immutable objects around ? Or do you perform defensive copies instead ?

Note: I am not trying to try and bend CS to the languages I know; Rather I want to know if it makes sense to reuse some of the concepts taken for granted in other languages.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:59:08+00:00Added an answer on May 25, 2026 at 9:59 pm

    I think the short answer to this is that JavaScript is versatile, but it’s unsafe. There are no static types, and nothing is immutable (except, as in your example, by being isolated in a different scope). Some people try to fight this looseness—Google, for example, heavily annotates their code, JavaDoc-style. But mainstream JavaScript programmers don’t. They rarely hide instance variables behind getters, or throw an exceptions when you call their API with a string when they expected a boolean. That’s partly for practical reasons—JS is the only language I know of where people commonly talk about their code’s byte size—but it also reflects the language’s surrounding culture, where documentation and tests are valued far above hand-holding.

    So, in short, I’d stick with

    constructor: (@x, @y) ->
    

    and write some good tests. You can’t protect against every possible misuse of your API, after all. Better to make its proper usage clear through good docs and tests.

    By the way, Underscore does provide an alternate syntax that lets you write your code in the desired order:

    _(list).remove ...
    

    Or you can extend the [Array] prototype. See Sugar.js for some fine examples.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.