Build your professional network on facebook via our app Go to app
 
 
 
Started by : Ashok Guduru, Tech Architect, SGT India Pvt. Ltd.   10 14 2008 06:51:43 +0000
Industry : IT ProductsFunctional Area : Programming Languages(Technology)
Activity:  3 views;  last activity : 07 06 2010 20:18:09 +0000

Subroutines and Functions (Commands and Queries)

 

Function: That always returns a value (return type is specified)

Subroutine: That never returns a value (void)

 

Based on the convention above the compiler gives an error if

 

1.       A subroutine returns a value

2.       The subroutine is used as a function i.e. written RHS of the variable (e.g. value = setValue())

3.        Function’s code doesn't pass all code paths with a return statement.

 

So similarly, I would like to have the compiler detect and flag an error or warning if the function is used like a subroutine. The return value should always either assigned to a variable, checked against some value in a condition (if etc.) or passed to some other function.

 

The caveat in enforcing this rule is, when applied on older programs written like this will now give errors. But newer versions of languages can have a setting in the compiler options/module level directives one like Option Explicit, Option Strict etc. in VB.NET. These way newer programs can be forced to written to include this new convention.

 

There is one more advantage of this is... Instead of throwing exceptions, programmers sometimes chose/use the return values to indicate the error conditions. This new convention forces the developer to handle the return values properly. Throwing exception is sometimes expensive. In this case user can use this new mechanism and still can have the error checks happen.

 

Compilers should be configurable with user definable rules/policies like above. For example, I would also like to get the warnings if function or sub has too many parameters. Having more than 2-3 parameters are evil to read and understand.

 
Share
 
 
  Rate : 
 
 
 
 
  0
 
 
 
 
 
1
1 Compiler should prevent use of a function like a subroutine

Compiler should prevent use of a function like a subroutine

No supporting Arguments for this idea
Add your argument:

Add your Idea
Idea* : 
Add your argument:
edit in rich text ...
Could not find any idea interesting in: "Compiler should prevent use of a function like a subroutine" ? Click here to add a new idea...

Found the idea contest "Compiler should prevent use of a function like a subroutine"  interesting ?  Click here to refer to your connections and communities
Leading HR Consulting Company
Leading HR Consulting Company
Viewers also viewed
If, as the old expression goes, imitation is the sincerest form of flattery then the top brass...
 
661 referals 11 votes, 1579 views
what is efferent between using STATIC keyword with out using Static keyword in java programming...
 
8 referals 5 answers, 187 views
AS BOTH VLSI EMBEDDED ARE CHIP DESIGN LEVEL PROGRAMMING WHICH ONE IS BETTER? MEANS WHICH HAVING...
 
1 referals 9 arguments, 5168 views
more...  
Recent Knowledge (2)
When we are watching news channels or any other channel or reading news papers you bump upon...
 
2022 referals 11 votes, 200 views
we all know the perils of talking on cell phones while driving. besides being hazourdous to...
 
290 referals 2 votes, 36 views
more...  
More From Author
Subroutines and Functions (Commands and Queries)   Function: That always returns a value (return type is specified) Subroutine: That never returns a value (void)   Based on the convention above the compiler gives an error if   1.        A...
Subroutines and Functions (Commands and Queries)   Function: That always returns a value (return type is specified) Subroutine: That never returns a value (void)   Based on the convention above the compiler gives an error if   1.        A...
An abstraction denotes the essential characteristics of an object that distinguish it from all other kinds of objects and thus provides crisply defined conceptual boundaries, relative to the perspective of the viewer. from Object-oriented analysis &...
more...