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 177293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:01:46+00:00 2026-05-11T14:01:46+00:00

In an imperative, object orients language, would make more sense to have mutable or

  • 0

In an imperative, object orients language, would make more sense to have mutable or immutable closures?

For example:

int i=5; function() f={print(i);}; f(); i=6; f(); 

If the closure is mutable, this would print:

5 6 

If it is immutable, it would print:

5 5 

I realize that even with immutable closures, you could still do this:

class I {int i;} I i=new I(); i.i=5; function() f={     I j=i;     print(j.i); }; f(); i.i=6; f(); 

So, would it be better to have mutable, or immutable closures, or have the option for both? Immutable closures seem easier to implement, so at this point, I think I’ll go with that, unless there is a good reason not to.

  • 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. 2026-05-11T14:01:46+00:00Added an answer on May 11, 2026 at 2:01 pm

    Imperative languages are typically built around the concept of state. Hence it makes more sense for language features to reflect that, including closures. Yes, this behavior can be confusing at times but it’s part of the problem and advantage to having state in your application.

    I think the best proof of this argument is to look at some of the more recent languages that have closure support. Both C# and VB.Net, imperative OO languages, chose to have mutable closures. While F#, a functional language, has immutable closures (mainly deriving from the idea that F# is immutable by default).

    Also what would it actually mean to have an immutable closure in an imperative language? Most people think of this as making the variables equivalent to C#’s readonly. Sure value types would be protected from modification, but what about mutable reference types. You wouldn’t be able to change where the variable pointed to, but you could call a mutating function and get a similar effect. For example.

    class Student {   public string Name { get; set; } }  void Example() {   var student = new Student() { Name = 'foo' };   Action() del = () =>      { student.Name = 'bar'; };   del(); } 

    This could be implemented with an immutable closure as I don’t actually modify where the variables point to. However I am clearly still doing a mutating operation.

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

Sidebar

Ask A Question

Stats

  • Questions 76k
  • Answers 76k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Are you looking for a bounding box? I'm not sure… May 11, 2026 at 3:12 pm
  • added an answer Check out this C++ code on CodeProject: essentially, you write… May 11, 2026 at 3:12 pm
  • added an answer Unfortunately this may not be of any help to you,… May 11, 2026 at 3:12 pm

Related Questions

I hope someone could help me on this. I want to add a month
Which techniques or paradigms normally associated with functional languages can productively be used in
As I have read through stackoverflow answers and questions I am getting the impression
Working on a project that parses a log of events, and then updates a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.