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

  • Home
  • SEARCH
  • 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 8689289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:36:31+00:00 2026-06-12T23:36:31+00:00

Go allows one to define methods separately from the struct/datatype they work on. Does

  • 0

Go allows one to define methods separately from the struct/datatype they work on. Does it mean just flexibility in placing the method definitions or something more?

I’ve heard Go’s struct/methods system being compared to monkey patching, but if I understand correctly, then you really can’t add methods to any existing type (struct), as methods must reside in same package as the type. Ie. you can monkey patch only the types which are under your control anyway. Or am I missing something?

In which cases would you define a type and its methods in separate source files (or in different parts of the same source file)?

  • 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-06-12T23:36:33+00:00Added an answer on June 12, 2026 at 11:36 pm

    This is an advantage of Go over type based languages : you can organize your files as you like :

    • you can put all the similar functions together, even if there are many receiver types
    • you can split a file which would otherwise be too big

    As frequently, Go didn’t add a constraint which was useless. So the answer could also be “why not” ?

    you really can’t add methods to any existing type (struct), as methods must reside in same package as the type

    If you could, you might not be able to determine which function to call in case of the same function name used on the same struct in two different packages. Or that would make certain packages incompatible.

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

Sidebar

Related Questions

Is there any mechanism in C# that allows one to define and declare an
Maybe I'm spoiled by Python, but does Octave allows one to assign the values
Just as there are functors like Action, Func, Comparison, is there one which allows
We have FireSymfony that allows one to view the Symfony, PHP variables in a
I have a program that only allows one instance of itself to run. I
The discussion here describes the display view in eclipse which allows one to to
The JavaScript sort function which takes a parameter allows one to pass in a
I'm trying to make an overlay with thickbox... it only allows one line captions...
Hudson CI server displays stability weather which is cool. And it allows one project
I'm curious about the ScreenSplitr app for jail-broken iPhones. This app allows one to

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.