question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rename the `this.name` to something other

See original GitHub issue

Because I need to do some weird stuff like this

const programName = this.name;
delete this.name;

// where `this` is the `prog` which is the "instance" of calling sade()
const handler = Object.assign(taskObj.handler, this);

// ! restore, because the help() needs it
this.name = programName;

return handler;

The case. I override a bit the .action method, for few reasons. And in this method I have above code, because I need to return the handler function and I where I use it I need also access to the “instance”.

And in general, just “name” isn’t that good. Probably this.programName makes more sense.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lukeedcommented, Jun 22, 2019

If you could extend Sade you’d still have this problem since the help text is built outside of the class, and that utility is passed the value. All it does it allow devs to manipulate the class in unforseen ways and then ping me when stuff breaks. No thanks, it does what it does

Really what you should have done here is initialize a singleton Sade instance and then exposed your own API that interfaced with the Sade instance privately. Would have worked just fine based on your description, and not been “ugly” - using it would have appeared like any other library usage.


I will take a look at this tomorrow. There are quite a few dependents now so I have to look thru some of them to see if any are reading the program name too.

0reactions
tunnckoCorecommented, Jun 22, 2019

Exactly, that’s again about design architecture problem of Sade. If it wasn’t doing a few things outside the class none of these issues would exist.

Really what you should have done here is initialize a singleton Sade instance and then exposed your own API that interfaced with the Sade instance privately.

Of course, I could create my own class or function and just replicate/mirror all the methods of Sade (like below), but that approach is unreliable and not future proof if Sade changes something (which probably won’t happen or won’t be so drastic, but still). Also, increases mine codebase unnecessarily and not because of some sane reason, but just because Sade wants to be closed for extending. Hence, the “O” in SOLID principles.

class Hela {
  constructor() {
    this.prog = sade('hela').version('3.0.0')
  }
  option(...args) {
    return this.prog.option(...args);
  }
  // and so on...
}

I will take a look at this tomorrow. There are quite a few dependents now so I have to look thru some of them to see if any are reading the program name too.

Cool, thanks. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change the name of your iPhone - Apple Support
Change the name of your iPhone · Go to Settings > General > About > Name. · Tap the Clear Text button ,...
Read more >
Rename a file - Microsoft Support
Open File Explorer by going to My Computer, or by pressing Windows Key + E on your keyboard. Find the file you want...
Read more >
Top 10 Reasons People Change Their Names | LegalZoom
A name change request can come about simply because a person doesn't like his or her name as given at birth. Perhaps they'd...
Read more >
Name change - Wikipedia
Name change is the legal act by a person of adopting a new name different from their current name. Name change certificate issued...
Read more >
Change your Google Account picture, name & other info
1. On your Android phone or tablet, open your device's Settings app . 2. Tap Google Manage your Google Account Personal info. 3....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found