The tag has no usage guidance.

learn more… | top users | synonyms

5
votes
3answers
168 views

Doesn't returning a Collection as Unmodifiable / Immutable unnecessarily break method scope?

Let's say I create a Collection in an instance method. I do not assign that reference to any instance variables. Rather, I just return it to the invoker. Then, I exit. Now, the only thing with a ...
0
votes
0answers
20 views

How can I make a Python deserialization function useable from another module? [migrated]

I have some serialization and deserialization code which works well within one module (and within the universe of classes I care about). E.g. class A(...): ... class B(...): ... def ...
14
votes
2answers
2k views

Why is it good programming practice to limit scope? [duplicate]

I'm relatively new to programming (July 2015), and I've always wondered why it's good programming practice to hide variables as much as possible. I've run into this question mainly recently when I ...
1
vote
2answers
94 views

What is the use case for shadowing variables?

One of the things the coffeescript programming language is criticized for is its treatment of variable declarations and scope (example). The answers to this question (and the blog I linked to above) ...
37
votes
9answers
3k views

Using compound statements (“{” … “}” blocks) to enforce variable locality [duplicate]

Introduction Many "C-like" programming languages use compound statements (code blocks specified with "{" and "}") to define a variables scope. Here is a simple example. for (int i = 0; i < 100; ...
5
votes
1answer
77 views

Pthread scheduling (System and Process)

I've read the operating system concepts 8th edition written by abraham silberschatz. However, I don't understand Pthread Scheduling. Thread-library schedules user-level-threads on LWP(Lightweight ...
6
votes
2answers
286 views

Automatic namespace resolution in C++

My question is focused on design, and the code included in this question is meant to clarify the problem I'm experiencing. I'm interested in conceptual level answers and not code in order to answer ...
2
votes
4answers
365 views

When was block scope for variables introduced to C, and why is it still frowned upon?

In light of the recent OBJ_obj2txt vulnerability in LibreSSL (which was found during the OpenSMTPD audit, and does not affect OpenSSL), it came to my attention that the memory leak issue likely ...
1
vote
2answers
188 views

Should I declare variables at the top of the function for reasons other than the scope rules?

In JavaScript, one should declare all variables at the beginning of the function to mitigate the risk of mistakes related to the fact that the scope of variables is a function. The following code ...
2
votes
4answers
243 views

Why shouldn't pure functions always be static and public? [duplicate]

What are the reasons, technical or otherwise, that pure functions (functions which do not rely on external state and have no side effects) should not always be public and static? When a static and ...
11
votes
3answers
360 views

How do you safely refactor in a language with dynamic scope?

For those of you who have the good fortune not to work in a language with dynamic scope, let me give you a little refresher on how that works. Imagine a pseudo-language, called "RUBELLA", that behaves ...
5
votes
4answers
379 views

Is Java package level scope useful?

I understand the idea of package scope, and at times have even thought I wanted it. However, every time I set down with a serious intent to try using it I discovered it did not fit the needs I ...
0
votes
5answers
326 views

Is it bad form to use the same variable name in different scopes?

Say you have some basic code where similar operations will take place in nearby lexical scopes. Take for example some simple pseudo code: variable = "foo" # Do something with variable if (True) { ...
0
votes
1answer
38 views

Scoping template variables in “has-a” (compositional) relationships

I'm developing a new templating language for PHP, and one of the features is an object-oriented approach to nested child templates. For example, I can declare an object of type HtmlBuilder like this: ...
2
votes
0answers
658 views

How does AngularJS manage scope in ng-repeats?

I have a table that has around 60 rows and 20 columns. Each cell has a directive with an isolated scope. I use 2 nested ng-repeats to generate the table (one for rows and one for columns), but I'm ...
0
votes
1answer
44 views

Scoping behavioral variations to dynamic extents

While reading a paper in the context of Aspect Oriented Programming, I encountered following statement: Aspects enable scoping variations in space (with a rich variety of static pointcuts), in ...
3
votes
2answers
223 views

Defensive copy in the client class or in the service class?

I have one service method that receive parameters as a Map. I will need to add new attributes to this map inside the service. If I pass the original Map object to the parameter instead of a copy, the ...
1
vote
2answers
172 views

Should I sacrifice code succintness to ensure the narrowest variable scope? [duplicate]

In many languages (e.g. both Perl and Java - which are the two languages I work most with) it is possible to narrow the scope of local variables by declaring them within a block. Although it adds ...
21
votes
6answers
2k views

Should I place functions that are only used in one other function, within that function?

Specifically, I'm writing in JavaScript. Let's say my primary function is Function A. If Function A makes several calls to Function B, but Function B is not used anywhere else, then should I just ...
2
votes
1answer
1k views

Where should variables be declared [duplicate]

Considering I have a for loop in a method of a class. Should the incremented variable be declared as member of the class, or should it be declared in the method it uses it(or even in the for loop, ...
1
vote
2answers
178 views

Scope vs Visiblity vs Lifetime vs Accessibility vs etc

I have been trying to understand what it means to say "scope of a named entity". In reading about scope, there are terms like visibility, lifetime, accessibility and more that are used. What is ...
9
votes
5answers
359 views

How to make it obvious that a function is being accessed from the outside?

This is a C specific question. I am trying to keep everything possible inside the translation unit boundaries, exposing only a few functions through the .h file. That is, I am giving static linkage to ...
3
votes
6answers
1k views

Nested Classes or Namespace

Why do need namespaces when we have nested classes. What can be done through namespaces, can also achieved through nested classes. so I don't understand the reasoning of having namespaces ?
4
votes
2answers
2k views

Event-driven vs. 'reference'-driven programming (i.e. in JavaScript)

I haven't been able to find the appropriate terminology to search for content on the web related to what I'm asking, so I'm hoping someone on here can at least point me in the right direction. I'm a ...
3
votes
2answers
222 views

How to pass parameters to a function in C

Suppose I'm writing a program in C in which several parameters are asked at the beginning of the execution to the user and then remain costant until the end. Now, I need to pass these parameters to ...
0
votes
1answer
649 views

Is there any way to limit the scope of a knockout.js application? [closed]

I have a legacy project which I have been approved to work in a knockout.js module. This is great, however the application is extremely complex and I need to use some of the pre-built form validation ...
3
votes
1answer
1k views

Does setting a function public affect the C# compiler's ability to inline the function as an optimization?

This could be either for the .NET or Mono compilers. I know that under certain conditions the compiler can inline functions (e.g. small, single call site, etc.) as an optimization. However, if the ...
3
votes
1answer
235 views

What is the advantage of determining scopes statically and using them dynamically in case of Python?

Firstly let me clarify that I know C and am learning Python. So my OOPS is kind of bad. I was reading the official tutorial and found this Although scopes are determined statically, they are ...
0
votes
2answers
604 views

Session or request scope for account details

I have a (browser based) web application. On each page, I want to have a little label and link in a corner that displays the user's username and other account information along with a logout button. ...
7
votes
4answers
820 views

Is the usage of internal scope blocks within a function bad style?

There are some (quite rare) cases where there is a risk of: reusing a variable which is not intended to be reused (see example 1), or using a variable instead of another, semantically close (see ...
1
vote
1answer
749 views

Nested classes vs namespaces

Is it good to use nested classes or should I use namespaces instead? In context: I have a templated codec loader and a codec have In objects and Out objects template<class TypeOfData> class ...
39
votes
8answers
2k views

What did programmers do before variable scope, where everything is global?

So, I am having to deal with seemingly archiac language (called PowerOn) where I have a main method, a few datatypes to define variables with, and has the ability to have sub-procedures (essentially ...
14
votes
9answers
2k views

Isn't class scope purely for organization? [duplicate]

Isn't scope just a way to organize classes, preventing outside code from accessing certain things you don't want accessed? More specifically, is there any functional gain to having public, protected, ...
4
votes
3answers
201 views

Misunderstanding Scope in JavaScript?

I've seen a few other developers talk about binding scope in JavaScript but it has always seemed to me like this is an inaccurate phrase. The Function.prototype.call and Function.prototype.apply don't ...
4
votes
2answers
1k views

What is the best way to handle last minute changes to product scope?

What is the best way to handle changes to product requirements or scope during or after User Acceptance Testing (UAT)? How dangerous is it to make those changes, and how can the danger be mitigated?
3
votes
9answers
2k views

Confusion of scope of a variable: Is Global Variable a solution? [duplicate]

I am newly learning C Programming. When we have a C Program with lot of functions, parameter passing, calling and all - It becomes a great problem as to which variable must be declared where. My ...
0
votes
7answers
253 views

How do you handle / what do you charge for documentation, training, warranty, changes in scope etc… [closed]

I am working with a client right now that wants me to sign a contact with a warranty for a year for no additional charge. As well as any reasonable changes he wants during the contract that are ...
2
votes
3answers
468 views

Scope of work contents in freelance development

One of my clients demanded to append screen shots of UI in the SOW. Also, I was asked to give a workflow diagram for the same. The project I am about to take is relatively small and my question is, ...
7
votes
3answers
13k views

What is meant by Scope of a variable?

I think of the scope of a variable as - "The scope of a particular variable is the range within a program's source code in which that variable is recognized by the compiler". That statement is ...
4
votes
2answers
877 views

What is required for a scope in an injection framework?

Working with libraries like Seam, Guice and Spring I have become accustomed to dealing with variables within a scope. These libraries give you a handful of scopes and allow you to define your own. ...
4
votes
2answers
301 views

How to deal with variables when extracting methods in to smaller methods?

This is an abstract question to clarify a refactoring concept in the ruby language. Assume in the real world that there would be many more variables and method in the Furniture Class and Refinish ...
17
votes
4answers
2k views

How to Determine # of Programmers needed for a project

How do you know how many programmers a particular project needs to be successful? The company I work for fulfills orders for client companies. We have written an in-house warehouse management ...
10
votes
7answers
834 views

Is there a term used when internal variables are declared public and accessible?

If someone writes code so that an internal variable $_fields is accessible without using getter/setter methods, is there a proper term used to describe that? Something polite enough to use with ...
5
votes
5answers
593 views

Is it OK to use dynamic typing to reduce the amount of variables in scope?

Often, when I am initializing something I have to use a temporary variable, for example: file_str = "path/to/file" file_file = open(file) or regexp_parts = ['foo', 'bar'] regexp = new ...
34
votes
5answers
3k views

Why are brackets required for try-catch?

In various languages (Java at least, think also C#?) you can do things like if( condition ) singleStatement; while( condition ) singleStatement; for( var; condition; increment ) ...
10
votes
5answers
930 views

Should you refactor existing code that is not broken in a project focused on new features?

Given a small project that aims to add new functionality to application, the changes introduced touch some existing code, involving updating these in certain areas. During implementation, I've found ...
8
votes
5answers
2k views

When would dynamic scoping be useful?

With dynamic scoping, a callee can access the variables of its caller. Pseudo C code: void foo() { print(x); } void bar() { int x = 42; foo(); } Since I have never programmed in a ...
1
vote
2answers
2k views

where is there a good description of the use of the word 'scope' in computer science? [closed]

Where is there a good description of the use of the word 'scope' in computer science? In this post of a question about the Java final reserved word one responder implies that scope is textual so each ...
5
votes
1answer
412 views

Scoping recommendations while developing in C

While developing a library using C, what are your recommendations about variable and function scoping? In C++, OOP and namespaces made the whole thing a lot easier. But how to do that with plain C? ...