Questions tagged [shadowing]

In computer programming, shadowing occurs when a variable declared within a certain scope (decision block, method or inner class) has the same name as a variable declared in an outer scope. This can lead to confusion, as it may be unclear which variable subsequent uses of the shadowed variable name refer to, which depends on the name resolution rules of the language.

One of the first languages to introduce variable shadowing was ALGOL, which first introduced blocks to establish scopes. It was also permitted by many of the derivative programming languages including C++ and Java.

The C# language breaks this tradition, allowing variable shadowing between an inner and an outer class, and between a method and its containing class, but not between an if-block and its containing method, or between case statements in a switch block.

237 questions
0
votes
2 answers

Is it possible to overwrite a Python built-in for the whole Python package?

I have a Python package with dozens of subpackages/modules. Nearly each of the modules uses open built-in Python function. I have written an own implementation of the file opening function and would like to "redirect" all open calls I have in the…
Alex Tereshenkov
  • 3,340
  • 8
  • 36
  • 61
0
votes
1 answer

Python, Bazel: Unittest in same folder as *submodule* named `math`: standard `math` is shadowed on Ubuntu, but not Mac?

We have example_package, which is a Python module itself, so we can access example_package.my_module in code. We also defined example_package.math, since we have some simple math routines. We have some tests, which Bazel will effectively place in…
Eric Cousineau
  • 1,944
  • 14
  • 23
0
votes
1 answer

Compile errors when implementing stream operators

I am trying to implement stream extraction operators for a stream class which inherits std::basic_iostream. Unfortunately I get compile errors I don't really understand. This is my simplified (non-functional) code: #include class…
user2328447
  • 1,807
  • 1
  • 21
  • 27
0
votes
1 answer

OCaml - Why doesn't the function change its output?

My professor showed us this code today but I can't seem to understand the result of it: # let a = 2;; val a : int = 2 # let f = fun x -> fun y -> if x = y then a + 2 else a - 10;; val : f 'a -> 'a -> int = # f 1 (2 - 1);; - : int = 4 # let a =…
AlexT
  • 589
  • 2
  • 9
  • 23
0
votes
1 answer

Shadowed method is not called

I have a class which i realized will not always correctly instantiate and as a quick fix, i figured i'd subclass it and shadow a few methods so that the program can continue to run without exploding. When i run the software, calls to the methods…
Brian Sweeney
  • 6,693
  • 14
  • 54
  • 69
0
votes
7 answers

Can you shadow AND override at the same time in C#?

Consider the following classes: abstract class Cog {} class BigCog: Cog {} class SmallCog: Cog {} abstract class Machine {} class BigMachine: Machine {} class SmallMachine: Machine {} Now all the machines work with cogs, but BigMachine only works…
Vilx-
  • 104,512
  • 87
  • 279
  • 422
0
votes
1 answer

What restricition imposed on cursor variable name in plsql?

I have executed following simple anonymous block in sql developer by expecting x number of rows to be deleted from "FOO" table however I ended up with unexpected outcome which in turn deleting entire rows. DECLARE type pkarray IS VARRAY(3) OF…
DaeYoung
  • 1,161
  • 6
  • 27
  • 59
0
votes
1 answer

How to find if a line intersects a voxel from a set of voxels?

I have an input as set of voxels with their centre's (x,y,z) given. I have a set of lines. I want to find if a line is intersected by any voxel in the given voxel set. (Yes/No Question). The current algorithm I am using is to traverse through the…
Rahul Sonanis
  • 55
  • 2
  • 7
0
votes
1 answer

Companion objects hide class -- bug or feature?

In Kotlin, the following seems to be reasonable code: data class Foo(val bar: String) { fun combine(other: Foo): Foo { return Foo(bar + other.bar) } companion object Foo { fun someHelper() {} } } However, it does…
Raphael
  • 9,779
  • 5
  • 63
  • 94
0
votes
0 answers

child instance parameters passing in parent class

I have parent class : class Parent { public void some() { return 10; } public String LAST_UPDATED_KEY = "parent_updated"; public String getLastUpdated(String key) { // do some stuff System.out.println(key); …
0
votes
1 answer

Getting SVN to shadow commits to a CVS repository

Is there a way to monitor commits to a CVS repository on a daily basis say, and for those changes to be replicated in a local SVN repository. Ideally maintaining commit comments. A little perl ditty maybe? Thanks, Steve.
Steve Jones
  • 141
  • 1
  • 5
0
votes
2 answers

JavaScript shadowing with initialization

Before I dive into the question I want to clarify that my use case involves patching a trans-compiler to generate a proper equivalent, hence the somewhat awkward question. I want to shadow an outside variable but initialize it to the same value as…
Alexander Tsepkov
  • 3,946
  • 3
  • 35
  • 59
0
votes
1 answer

Drawing circular gradient shade outlining shape

So, I have a white circular shape described in the following code:
FabioR
  • 696
  • 9
  • 18
0
votes
1 answer

NodeJs - cant access updated value of array outside function scope

I'm new to node and I'm trying to fetch the twitter id of a group of users. The module accepts an array of screen names and iterates over it to get the userId and pushes them to an array. The problem is, I can't return that array. I can access it…
0
votes
1 answer

Javascript prototype property shadowed

I am a little confused with the Javascript prototyping mechanics. I have the following code : function Person () { this.name = "no name"; this.setName = function (n) { this.name = n; } } function Student () { this.id =…
landunder
  • 372
  • 1
  • 5
  • 17