30,454 questions
Advice
0
votes
2
replies
85
views
Method-body equivalent of lambda expression
Following is a part of the execution sequence when a middleware gets configured in ASP.NET Core -
// my code
app.Use(some middleware);
// class UseExtensions / namespace Microsoft.AspNetCore.Builder
...
2
votes
1
answer
121
views
Inheriting optional methods from a type
I'd like to have a class with a bunch of optional methods derived from some type, then implement some of those in some subclasses:
type OptionalPrototypeMethods = {
f(): number,
}
interface Cls ...
5
votes
1
answer
82
views
Externally provided method not receiving self
While methods are usually defined inside the class block with def func(self, ...):, this is not required:
def method(self):
return self.x
class Foo:
def __init__(self, x):
self.x = x
...
Advice
0
votes
4
replies
113
views
Does the finally block run when returning inside try, and what happens if finally also returns?
I have a question about how try/finally behaves when using return statements in C#.
Consider the following methods:
public int Test()
{
return 12;
}
public int Test2()
{
try
{
...
-8
votes
1
answer
151
views
Wrapping a method in a try-catch block but unsure where to declare a char variable
I have this method in my program, it is meant to register the gender of the user for later on in the program (with Male and Female as the only valid options):
public static void Main(string[] args)
{
...
-7
votes
1
answer
105
views
Formatting the first symbol of a string to be upper case - a private method or formatting on the go? [closed]
In a class that has a bunch of functions, should I be making a separate private method specifically for formatting or should I just be formatting in every function that requires a string to be ...
3
votes
1
answer
66
views
Typescript method overload lost
I'm using typescript in a project which uses BackboneJS and in a certain case, a method overload gets lost.
I narrowed it down to this case:
class Model {
set<A extends string>(key: A, value: ...
0
votes
1
answer
64
views
How can I forbid method redefenition in TCL OO class?
I would like that method redefenition would result in failure and script execution stop. Like any other common error.
In the following example I want to see that method print cannot be redefined.
oo::...
3
votes
1
answer
204
views
What does 0 mean in someList.toArray(new AnotherClass[0])?
In Java we have toArray() method which will return Object[]. If I want to return another data type I need to pass it to parameters like this
SomeClass.SomeList.toArray(new AnotherClass[0]);
What does ...
0
votes
0
answers
157
views
Detect unimplemented class methods without a program failing to link
Suppose I am working on a library with a decent number of classes, most of them having a bunch of methods, in addition to the basic ctors and dtor. For reasons, the method implementations are spread ...
1
vote
1
answer
77
views
How to type class method arguments based on function arguments passed to class constructor
I have class example:
export class Test{
private func: (...args: any[]) => void;
constructor(func: (...args: any[]) => void) {
this.func = func;
}
method(...args: any[]) {...
0
votes
1
answer
102
views
PHP vs C++: How do I declare class constants which are used in method calls in C++? [duplicate]
I come from PHP where I usually never have global constants. For instance, if I have the class Users and the method add(int $status, string $username) then the status of the user is a constant only ...
0
votes
3
answers
127
views
Minifiying javascript file with webpack breaks vue functionality (specifically with method calls on class instance)
I am working on an ASP.NET project that uses Vue.js and jQuery. I have a JavaScript file (fields.js) that defines several classes (e.g., Users, Fields) and initializes a Vue instance. When I use the ...
-1
votes
0
answers
43
views
What does this reduce() function do in counting elements from an array? [duplicate]
I'm trying to understand how the reduce() function works in this example:
const fruits = ['apple', 'banana', 'apple', 'orange', 'banana', 'apple'];
const count = fruits.reduce((tally, fruit) => {
...
-9
votes
1
answer
151
views
Using the .find() function in a loop [closed]
I was trying to get the last word of the sentence using the .find() method in a loop.
My code:
sentence = "please write a program which keeps asking the user for words"
index = 0
substring = ...