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
Post Your Resume Now !
Web content developer
Oracle Applications 11.x DBA, Inventory, Purchasing, Order Management, Oracle Apps SCM Functional Consultant, Arowana Consulting, Bangalore
IT SALES, Product sales, Animation, IT SALES / IT Animation Sales, Arowana Consulting, Los Angeles, California
Viewers also viewed
Age differences are more important than cohort effect vs Cohort effects can dominate age differences
 
748 referals 11 arguments, 415 views
Does Functional Guys requires a bit of Technical Knowledge Or Does Technical Guys requires a bit...
 
1105 referals 6 arguments, 64 views
Wide availability of talent and cost advantage has helped India emerge as a "skill hub" not only...
 
100 referals 3 votes, 69 views
more...  
Recent Knowledge (11)
The question is simple. What makes you smile? Let us stop fighting on various topics and discuss...
 
1697 referals 27 votes, 361 views
To get growth one decides of studying further. Some people might be willing to do it after...
 
1797 referals 4 votes, 81 views
I have seen some queries coming in very regularly about job offers. Whena person gets job in two...
 
1952 referals 17 votes, 384 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...