overloads in vb.net [duplicate] - vb.net

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
“Overloads” keyword in VB.NET
what exactly overloads signifies in vb.net coz even if i am not writing the overloads in derived class function its working in the similar manner when i am writing it.

Function overloading allows more than one function to be defined with the same name in the same class, as long as the arguments are different. Not to be confused with function overriding where functions have the same number, type of arguments its the implementations in the derived classes that differs.

I believe that the overloads keyword in vb.net is completely optional, and is there only to support better readability of the code.
There is an all-or-nothing rule, however, so if you use it for one method, you have to use it for all overloading methods.

Related

Why are certain Kotlin library functions (e.g., some extension functions in String.kt) marked as inline even if they are no higher-order functions? [duplicate]

This question already has answers here:
Why use inline without lambdas
(3 answers)
Closed 1 year ago.
The Kotlin documentation itself states the following:
If an inline function has no inlinable function parameters and no reified type parameters, the compiler will issue a warning, since inlining such functions is very unlikely to be beneficial.
Both statements, no inlinable function parameters and no reified type parameters, are true for, for example, the following extension methods in String.kt:
public inline fun String.reversed(): String
public inline fun String.slice(indices: Iterable<Int>) : String
public inline fun CharSequence.random(): Char
Can anyone explain me a specific reason why the language designers probably made the decisions to mark these methods as inline? Thanks.
As #somethingsomething pointed out in the comments, this question has been answered in a similar question before.
The answer there (by a JetBrains employee) was:
This particular function and a few others in kotlin-stdlib are marked as #InlineOnly so that they are not present in the actual stdlib class files and are only available for the Kotlin compiler to inline them. The goal that is achieved in this way is reducing the methods count in the artifacts, which matters for Android.
The #InlineOnly annotation is also discussed in this question.

What are these things called / for? <something("string")> [duplicate]

This question already has answers here:
VB.NET Brackets () {} [] <>
(4 answers)
Closed 3 years ago.
When I was writing a program that manipulated Active Directory, I found I needed to extend the GroupPrincipal class, and found some code that told me how to do this.
<DirectoryRdnPrefix("CN")>
<DirectoryObjectClass("group")>
Public Class GroupPrincipalEx
Inherits DirectoryServices.AccountManagement.GroupPrincipal
Public Sub New(context As PrincipalContext)
MyBase.New(context)
End Sub
Public Sub New(context As PrincipalContext, samAccountName As String)
...
What are the parts in angle-brackets called? What are they for? Where can I learn more about them.
I'm not asking about something specific to this case, my program works just fine. I just don't know what this language feature is, or does, or when to use it in future cases.
These are Attributes. Attributes can be evaluated by using Reflection.
Attributes
Attributes provide a powerful method of associating metadata, or
declarative information, with code (assemblies, types, methods,
properties, and so forth). After an attribute is associated with a
program entity, the attribute can be queried at run time by using a
technique called reflection.
Reflection
The classes in the System.Reflection namespace, together with
System.Type, enable you to obtain information about loaded assemblies
and the types defined within them, such as classes, interfaces, and
value types. You can also use reflection to create type instances at
run time, and to invoke and access them.

What are Modules in VB.NET and what are its advantages? [duplicate]

This question already has answers here:
Classes vs. Modules in VB.NET
(8 answers)
VB.NET What is the purpose of a class or module?
(7 answers)
Closed 9 years ago.
I have been new to Visual Basic. Why exactly do we use a module in VB.NET?
What would be a small example of a module and calling it one of the form?
A Module in VB.Net is essentially a grouping a methods and fields. These members can be accessed without qualification anywhere that the module itself is accessible. This mechanism is actually how many of the standard VB operators ChDir, ChDrive, CurDir are implemented. There is a module in the VB runtime named FileSystem which defines all of these operations
The main advantages / differences between Module and Class are the following
It's a declarative grouping of functions that aren't associated with instances of an object
It's the only way to define extension methods in VB.Net
No need for a redundant qualifier on every usage of a project helper method
No need to protect a module from accidental instantiation by the developer. It's by definition not creatable

Is it possible to define a C function at runtime? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Dynamically creating functions in c
Here is an example of what I'd like to do:
void attribute((constructor)) someFunction() {
// Would be nice to define C function "someFunction2" somehow here.
}
I know class_addMethod allows adding C functions to Objective-C classes during runtime.
Is it possible to add C function to C main space?
Please, don't tell me I'm wrong if I'm thinking about this way of doing things - I am interested in it rather for educational purposes.
No. A C function consists of a name and a body. The compiler transforms the body to a binary piece of executable code that will be mapped to some address when a process is created from the executable. The name is used by the static and dynamic linkers as an alias to this address.
At runtime both concepts aren't really of much interest. The executable is loaded and names are resolved, so there's little use in creating them dynamically.
On iOS it would even be impossible to create new function implementations as the kernel disallows to make memory executable.

Function overloading vs. default parameters in VB.NET?

In VB.NET, which is better to use: function overloading or default parameters?
if the parameters are optional (i.e. the overloads are a subset of the parameters that the full procedure signature accepts) then default or optional parameters would make more sense.
If the overload is allowing a different type for the parameter or is a semantically different parameter that will be interpreted differently by the routine then overloads would make more sense.
Is the code going to be used by other languages? If so, that swings the balance towards overloads while still bearing Hamish's answer in mind. In particular, C# doesn't support optional parameters - yet...
Admittedly this wouldn't actually prevent someone using your code from C#, it just might be a pain for them.
If there are a lot of parameters and they logically represent something, you might want to consider encapsulating them together, in the same way that Process works with ProcessStartInfo. That's particularly nice from C# due to object initializers.
If this is for construction, you might also consider the builder pattern as a variant of this. For instance, in Protocol Buffers I can do something like:
Person jon = new Person.Builder { Name="Jon", Age=32,
Spouse="Holly", Kids=3 }.Build();
which ends up being very readable while still creating a person in one go (in one expression, and without having to mutate the person itself - indeed the message type is immutable; it's only the builder which isn't).
FYI
If you want to add a parameter to a function or method that is called from other assemblies, then:
You can overload by making an additional function with the extra parameter.
Or you can add an optional parameter, BUT: You have to recompile all of the assemblies that call this function, even if they don't need to use the new optional parameter! This is not usually what people expect (expecially those used to how VB6 works). Basically, you can't slip in a new optional parameter to a function and expect it to be totally backwards compatible. Also, as I understand it, if you change what the default value is, you need to rebuild all calling assemblies for the change to work.