Tutorial by Examples: def

A Regexp can be created in three different ways in Ruby. using slashes: / / using %r{} using Regex.new #The following forms are equivalent regexp_slash = /hello/ regexp_bracket = %r{hello} regexp_new = Regexp.new('hello') string_to_match = "hello world!" #All of th...
Equals is declared in the Object class itself. public virtual bool Equals(Object obj); By default, Equals has the following behavior: If the instance is a reference type, then Equals will return true only if the references are the same. If the instance is a value type, then Equals will...
Avoid unnecessary operations and method calls wherever you can, especially in a method which is called many times a second, like Update. Distance/Range Checks Use sqrMagnitude instead of magnitude when comparing distances. This avoids unnecessary sqrt operations. Note that when using sqrMagnitude,...
A Clojure function can be defined to take an arbitrary number of arguments, using the symbol & in its argument list. All remaining arguments are collected as a sequence. (defn sum [& args] (apply + args)) (defn sum-and-multiply [x & args] (* x (apply + args))) Calling: =&gt...
We often encounter a situation where a property we're trying to extract doesn't exist in the object/array, resulting in a TypeError (while destructuring nested objects) or being set to undefined. While destructuring we can set a default value, which it will fallback to, in case of it not being found...
Appearance : Trying to access an array by a key that does not exist in the array Possible Solution : Check the availability before accessing it. Use: isset() array_key_exists()
Although available, defining a class from scratch is not recommended in modern Perl. Use one of helper OO systems which provide more features and convenience. Among these systems are: Moose - inspired by Perl 6 OO design Class::Accessor - a lightweight alternative to Moose Class::Tiny...
def foo(li=[]): li.append(1) print(li) foo([2]) # Out: [2, 1] foo([3]) # Out: [3, 1] This code behaves as expected, but what if we don't pass an argument? foo() # Out: [1] As expected... foo() # Out: [1, 1] Not as expected... This is because default arguments of function...
One of the most common errors in compilation happens during the linking stage. The error looks similar to this: $ gcc undefined_reference.c /tmp/ccoXhwF0.o: In function `main': undefined_reference.c:(.text+0x15): undefined reference to `foo' collect2: error: ld returned 1 exit status $ So l...
Defines a new type based on an existing type. Its syntax mirrors that of a variable declaration. /* Byte can be used wherever `unsigned char` is needed */ typedef unsigned char Byte; /* Integer is the type used to declare an array consisting of a single int */ typedef int Integer[1]; /* Nod...
A simple example: CL-USER> (defun make-apply-twice (fun) "return a new function that applies twice the function`fun' to its argument" (lambda (x) (funcall fun (funcall fun x)))) MAKE-APPLY-TWICE CL-USER> (funcall (make-apply-twice #'1+) 3) 5 ...
As we know we can declare an array with default values: int[] arr = new int[10]; This will create an array of 10 integers with each element of the array having value 0 (the default value of type int). To create an array initialized with a non-default value, we can use Enumerable.Repeat from the...
A source code file is a (generally) plain text file which is to processed by the compiler. A source code file may contain up to one main program and any number of modules and external subprograms. For example, a source code file may contain the following module mod1 end module mod1 module mod...
Simple one-liners may be specified as command line arguments to perl using the -e switch (think "execute"): perl -e'print "Hello, World!\n"' Due to Windows quoting rules you can't use single-quoted strings but have to use one of these variants: perl -e"print qq(Hello, W...
Typedefs are declarations which have the keyword typedef in front and before the type. E.g.: typedef int (*(*t0)())[5]; (you can technically put the typedef after the type too - like this int typedef (*(*t0)())[5]; but this is discouraged) The above declarations declares an identifier for a typ...
$ git show # equivalent to 'git show HEAD' 'HEAD' names the commit on which you based the changes in the working tree, and is usually the symbolic name for the current branch. Many (but not all) commands that take revision parameter defaults to 'HEAD' if it is missing.
It is possible to change Code Folding preference to suit your need. Thus code folding can be set enable/unable for specific constructs (ex: if block, for loop, Sections ...). To change folding preferences, go to Preferences -> Code Folding: Then you can choose which part of the code can be f...
C++14 Those following duration user literals are declared in the namespace std::literals::chrono_literals, where both literals and chrono_literals are inline namespaces. Access to these operators can be gained with using namespace std::literals, using namespace std::chrono_literals, and using names...
C++14 Those following string user literals are declared in the namespace std::literals::string_literals, where both literals and string_literals are inline namespaces. Access to these operators can be gained with using namespace std::literals, using namespace std::string_literals, and using namespa...
A default constructor is a type of constructor that requires no parameters when called. It is named after the type it constructs and is a member function of it (as all constructors are). class C{ int i; public: // the default constructor definition C() : i(0){ // member initial...

Page 11 of 27