Skip to main content

Advertisement

Log in

To var or not to var: how do C# developers use and misuse implicit and explicit typing?

  • Published:
Software Quality Journal Aims and scope Submit manuscript

Abstract

When implicit typing with the “var” keyword was introduced into C#, it prompted contradictory opinions among developers. This paper starts by explaining the difference between implicit and explicit typing and then provides an overview of developers’ opinions and guidelines that are available online. This paper then reports on the results of a study that investigated how C# developers use and misuse implicit and explicit typing. This study involved analyzing the source code of 10 different open-source software projects including more than 16,500,000 lines of code and more than 930,000 variables. This study investigated to what extent developers use a form of typing that affects the readability of a variable’s type and the length of its declaration. It also investigated whether or not there is an adoption of a consistent set of guidelines in general and across each software project. A tool called “Code Analysis and Refactoring Engine for C#” (Care#) was developed and used to conduct the code analysis for this study.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Fig. 1
Fig. 2
Fig. 3
Fig. 4
Fig. 5
Fig. 6
Fig. 7
Fig. 8
Fig. 9
Fig. 10
Fig. 11
Fig. 12
Fig. 13
Fig. 14

Similar content being viewed by others

References

  • Al Dallal, J., & Abdin, A. (2018). Empirical evaluation of the impact of object-oriented code refactoring on quality attributes: a systematic literature review. IEEE Transactions on Software Engineering, 44(1), 44–69.

    Article  Google Scholar 

  • Albahari, J., & Albahari, B. (2016). C# 6.0 in a nutshell. Oreilly.

  • Binkley, D. (2007). Source code analysis: a road map. in: Future of software engineering, 2007. FOSE’07. IEEE, pp. 104–119.

  • Butler, S., Wermelinger, M., Yu, Y., & Sharp, H. (2010). Exploring the influence of identifier names on code quality: an empirical study. In Software maintenance and reengineering (CSMR), 2010 14th European Conference On. IEEE, pp. 156–165.

  • Butler, S., Wermelinger, M., & Yu, Y. (2015). Investigating naming convention adherence in Java references. In Software maintenance and evolution (ICSME), 2015 IEEE International Conference On. IEEE, pp. 41–50.

  • Cabral, B., & Marques, P. (2007). Exception handling: a field study in Java and NET. In: E. Ernst, (Ed.), ECOOP 2007—object-oriented programming: 21st European conference, Berlin, Germany, July 30–august 3, 2007. Proceedings. Springer: Berlin, pp. 151–175. https://doi.org/10.1007/978-3-540-73589-2_8.

  • Cacho, N., Barbosa, E. A., Araujo, J., Pranto, F., Garcia, A., Cesar, T., Soares, E., Cassio, A., Filipe, T., & Garcia, I. (2014a). How does exception handling behavior evolve? An exploratory study in Java and C# applications, in: Software maintenance and evolution (ICSME), 2014 IEEE International Conference On. IEEE, pp. 31–40.

  • Cacho, N., César, T., Filipe, T., Soares, E., Cassio, A., Souza, R., Garcia, I., Barbosa, E. A., & Garcia, A. (2014b). Trading robustness for maintainability: an empirical study of evolving C# programs, in: Proceedings of the 36th International Conference on Software Engineering, ICSE 2014. ACM: New York, pp. 584–595. https://doi.org/10.1145/2568225.2568308.

  • Callaú, O., Robbes, R., Tanter, É., & Röthlisberger, D. (2013). How (and why) developers use the dynamic features of programming languages: the case of small talk. Empirical Software Engineering, 18(6), 1156–1194. https://doi.org/10.1007/s10664-012-9203-2.

    Article  Google Scholar 

  • Capek, P., Král, E., & Senkerik, R. (2015). Towards an empirical analysis of .NET framework and C# language features’ adoption. In Computational science and computational intelligence (CSCI), 2015 international conference on. IEEE, pp. 865–866.

  • Channel9. (2010). How much do you use “var” in C#? [WWW document]. URL https://channel9.msdn.com/Forums/Coffeehouse/How-much-do-you-use-var-in-C. Accessed 1.12.17.

  • Coleman, D., Ash, D., Lowther, B., & Oman, P. (1994). Using metrics to evaluate software system maintainability. IEEE Comput, 27(8), 44–49.

    Article  Google Scholar 

  • Deissenboeck, F., & Pizka, M. (2006). Concise and consistent naming. Software Quality Journal, 14(3), 261–282.

    Article  Google Scholar 

  • Deitel, P., & Deitel, H. (2018). Visual C# how to program (6th ed.). Pearson.

  • Fowler, M. (1999). Refactoring: improving the design of existing code. Addison-Wesley.

  • Ge, X., DuBose, Q. L., & Murphy-Hill, E. (2012). Reconciling manual and automatic refactoring. In Proceedings of the 34th international conference on software engineering. IEEE Press, pp. 211–221.

  • Ghosh, S., & Rana, A. K. (2011). Comparative study of the factors that affect maintainability. International Journal on Computer Science and Engineering, 3, 3763.

    Google Scholar 

  • Griswold, W. G. (1991). Program restructuring as an aid to software maintenance. University of Washington.

  • Griswold, W. G., & Notkin, D. (1993). Automated assistance for program restructuring. ACM Transactions on Software Engineering and Methodology, 2(3), 228–269. https://doi.org/10.1145/152388.152389.

    Article  Google Scholar 

  • Hashim, K. (1996). A software maintainability attributes model. Malaysian Journal of Computer Science, 9, 92–97.

    Google Scholar 

  • Hejlsberg, A. (2008). Anders Hejlsberg talks about the C# Language [WWW Document]. URL https://www.youtube.com/watch?v=dc-YDS4JVA8. Accessed 11.12.17.

  • IC#Code. (2016). SharpDevelop [WWW document]. URL http://www.icsharpcode.net/OpenSource/SD/Default.aspx. Accessed 10.23.17.

  • JetBrains. (2018a). ReSharper [WWW document]. URL https://www.jetbrains.com/resharper. Accessed 1.3.08.

  • JetBrains. (2018b). ReSharper “var” keyword [WWW document]. URL https://www.jetbrains.com/help/resharper/Using_var_Keyword_in_Declarations.html#preferences. Accessed 1.3.18.

  • Kim, D., Murphy-Hill, E. R., Parnin, C., Bird, C., & Garcia, R. (2013). The reaction of open-source projects to new language features: an empirical study of C# generics. Journal of Object Technology, 12, 1–1.

    Article  Google Scholar 

  • Lawrie, D., Feild, H., & Binkley, D. (2007). Quantifying identifier quality: an analysis of trends. Empirical Software Engineering, 12(4), 359–388.

    Article  Google Scholar 

  • Lientz, B. P., & Swanson, E. B. (1980). Software maintenance management: a study of the maintenance of computer application software in 487 data processing organizations. Addison-Wesley.

  • Lippert, E. (2011). Uses and misuses of implicit typing [WWW Document]. URL https://blogs.msdn.microsoft.com/ericlippert/2011/04/20/uses-and-misuses-of-implicit-typing. Accessed 4.20.11.

  • Ma, L., Zhang, C., Yu, B., & Sato, H. (2017). An empirical study on the effects of code visibility on program testability. Software Quality Journal, 25(3), 951–978. https://doi.org/10.1007/s11219-016-9340-8.

    Article  Google Scholar 

  • Marcus, A., & Maletic, J. I. (2001). Identification of high-level concept clones in source code, in: Automated software engineering, 2001.(ASE 2001). Proceedings. 16th annual international conference on. IEEE, pp. 107–114.

  • Martin, R. C. (2009). Clean code: a handbook of agile software craftsmanship. Pearson Education.

  • Mens, T., et al. (2004). A survey of software refactoring. IEEE Transactions on Software Engineering, 30(2), 126–139.

    Article  Google Scholar 

  • Microsoft. (2015a). C# coding conventions (C# programming guide) [WWW document]. URL https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/inside-a-program/coding-conventions. Accessed 11.30.17.

  • Microsoft. (2015b). Var (C# reference) [WWW document]. URL https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/var. Accessed 11.30.17.

  • Microsoft. (2015c). Implicitly typed local variables (C# programming guide) [WWW document]. URL https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/implicitly-typed-local-variables. Accessed 11.30.17.

  • Microsoft. (2017a). Net core [WWW Document]. URL https://www.microsoft.com/net/core. Accessed 10.23.17.

  • Microsoft. (2017b). Roslyn [WWW document]. URL https://roslyn.codeplex.com. Accessed 10.23.17.

  • MixERP Inc. (2015). MixERP [WWW Document]. URL https://mixerp.org. Accessed 10.23.17.

  • MonoDevelop Project. (2017). MonoDevelop [WWW Document]. URL www.monodevelop.com. Accessed 10.23.17.

  • Murphy-Hill, E., & Black, A. P. (2008). Refactoring tools: fitness for purpose. IEEE Software, 25(5), 38–44.

    Article  Google Scholar 

  • NHibernate Community. (2017). NHibernate [WWW Document]. URL http://nhibernate.info. Accessed 10.23.17.

  • Okur, S., & Dig, D. (2012). How do developers use parallel libraries? In Proceedings of the ACM SIGSOFT 20th international symposium on the foundations of software engineering, FSE ‘12. ACM, New York, NY, USA, pp. 54:1–54:11. https://doi.org/10.1145/2393596.2393660.

  • Okur, S., Hartveld, D. L., Dig, D., van Deursen, A. (2014). A study and toolkit for asynchronous programming in C#. In Proceedings of the 36th international conference on software engineering. ACM, pp. 1117–1127.

  • Oliveira, J., Borges, D., Silva, T., Cacho, N., & Castor, F. (2018). Do android developers neglect error handling? A maintenance-centric study on the relationship between android abstractions and uncaught exceptions. Journal of Systems and Software, 136, 1–18.

    Article  Google Scholar 

  • Opdyke, W. F. (1992). Refactoring: a program restructuring aid in designing object-oriented application frameworks. University of Illinois at Urbana-Champaign.

  • OpenRA. (2017). [WWW Document]. URL http://www.openra.net. Accessed 10.23.17.

  • Parr, T. (2018). ANTLR [WWW Document]. URL http://www.antlr.org. Accessed 4.1.18.

  • Peercy, D. E. (1981). A software maintainability evaluation methodology. IEEE Transactions on Software Engineering, SE-7(4), 343–351.

    Article  Google Scholar 

  • Poole, C., Prouse, R., Busoli, S., & Colvin, N. (2017). NUnit [WWW Document]. URL http://nunit.org. Accessed 10.23.17.

  • Shadowsocks Community. (2017). Shadowsocks [WWW Document]. URL https://shadowsocks.org. Accessed 10.23.17.

  • ShareX Team. (2017). ShareX [WWW Document]. URL https://getsharex.com. Accessed 10.23.17.

  • Shore J. (2004). Design debt. Software Profitability.

  • Soares, G., Gheyi, R., Serey, D., & Massoni, T. (2010). Making program refactoring safer. IEEE Software, 27(4), 52–57.

    Article  Google Scholar 

  • Szoke, G., Nagy, C., Fülöp, L. J., Ferenc, R., & Gyimóthy, T. (2015). FaultBuster: an automatic code smell refactoring toolset, in: Source code analysis and manipulation (SCAM), 2015 IEEE 15th international working conference on. IEEE, pp. 253–258.

  • TIOBE. (2017). TIOBE programming community index [WWW document]. URL https://www.tiobe.com/tiobe-index. Accessed 12.26.17.

  • Various. (2014). Debate on typing: unity forum [WWW document]. URL https://forum.unity.com/threads/c-microsoft-suggests-using-var-instead-of-a-type.232732/. Accessed 11.30.17.

  • Vidal, S. A., Marcos, C., & Díaz-Pace, J. A. (2016). An approach to prioritize code smells for refactoring. Automated Software Engineering, 23(3), 501–532.

    Article  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Pierre A. Akiki.

Additional information

Publisher’s Note

Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Rights and permissions

Reprints and permissions

About this article

Check for updates. Verify currency and authenticity via CrossMark

Cite this article

Akiki, P.A. To var or not to var: how do C# developers use and misuse implicit and explicit typing?. Software Qual J 27, 1175–1207 (2019). https://doi.org/10.1007/s11219-018-9426-6

Download citation

  • Published:

  • Issue Date:

  • DOI: https://doi.org/10.1007/s11219-018-9426-6

Keywords

Navigation