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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:43:20+00:00 2026-05-11T09:43:20+00:00

Recently I asked a question about how to clean up what I considered ugly

  • 0

Recently I asked a question about how to clean up what I considered ugly code. One recommendation was to create an Extension Method that would perform the desired function and return back what I wanted. My first thought was ‘Great! How cool are Extensions…’ but after a little more thinking I am starting to have second thoughts about using Extensions…

My main concern is that it seems like Extensions are a custom ‘shortcut’ that can make it hard for other developers to follow. I understand using an Extension can help make the code syntax easier to read, but what about following the voice behind the curtain?

Take for example my previous questions code snippet:

if (entry.Properties['something'].Value != null)   attribs.something = entry.Properties['something'].Value.ToString(); 

Now replace it with an Extension:

public static class ObjectExtensions {     public static string NullSafeToString(this object obj)     {         return obj != null ? obj.ToString() : String.Empty;     } } 

and call using the syntax:

attribs.something = entry.Properties['something'].Value.NullSafeToString(); 

Definetely a handy way to go, but is it really worth the overhead of another class object? And what happens if someone wants to reuse my code snippet but doesn’t understand Extension? I could have just as easily used the syntax with the same result:

attribs.something = (entry.Properties['something'].Value ?? string.Empty).ToString() 

So I did a little digging and found a couple of articles that talked about the pros/cons of using Extensions. For those inclined have a look at the following links:

MSDN: Extension Methods

Extension Methods Best Practice

Extension Methods

I can’t really decide which is the better way to go. Custom Extensions that do what I want them to do or more displayed code to accomplish the same task? I would be really interested in learning what ‘real’ developers think about this topic…

  • 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-11T09:43:20+00:00Added an answer on May 11, 2026 at 9:43 am

    Personally I think the ‘problems’ of extension method readability are vastly overstated. If you concentrate on making your code easy to read in terms of what it’s doing, that’s more important most of the time than how it’s doing it. If the developer wants to trace through and find out what’s actually happening behind the scenes, they can always click through to the implementation.

    My main problem with extension methods is their discovery method – i.e. via a specified namespace instead of a specified class. That’s a different matter though 🙂

    I’m not suggesting that you put in extension methods arbitrarily, but I would seriously consider how often you need to know how every expression in a method works vs skimming through it to see what it does in broader terms.

    EDIT: Your use of terminology may be misleading you slightly. There’s no such thing as an ‘extension object’ – there are only ‘extension methods’ and they have to exist in static types. So you may need to introduce a new type but you’re not creating any more objects.

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

Sidebar

Ask A Question

Stats

  • Questions 64k
  • Answers 64k
  • 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 I am not sure I understand your question correctly, but… May 11, 2026 at 10:56 am
  • added an answer You could look at the filter attribute that you can… May 11, 2026 at 10:55 am
  • added an answer No. DLL_B will not be unloaded. The LoadLibrary() call made… May 11, 2026 at 10:55 am

Related Questions

I recently asked a question about IIf vs. If and found out that there
I recently asked a question about what I called method calls. The answer referred
I recently asked a question about Oracle Encryption. Along the way to finding a
I recently asked a question about tracing Linq-to-Entities I think that one of the
I recently asked a question about functional programming, and received (good!) answers that prompted
I've recently asked a question on StackoverFlow about the MVC: Can the MVC Design
A question was asked recently about removing SourceSafe integration from Visual Studio 6 .
I recently asked this question and worked out that the reason a single email
Recently I was asked this during a job interview. I was honest and said
Why are 'out' parameters in .NET a bad idea? I was recently asked this,

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.