Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » U++ Developers corner » Source Code Efficiency Minor Issue
Source Code Efficiency Minor Issue [message #58529] Wed, 08 June 2022 18:46 Go to next message
aminhere is currently offline  aminhere
Messages: 3
Registered: June 2022
Location: Waterloo
Junior Member
Hello friends,

I recently discovered the U++ framework and I am having great success using it. I would like to sincerely thank the developers for all the hard work.

One recurring issue I have noticed while examining some code constructs like for example 'CodeEditor.cpp' is that all code does not make use of [else if] statements. For example, let us consider this piece of code from the previously mentioned cpp file:
-----------------------------------------------------
if(IsSelection() && auto_enclose) {
	if(code == '(') {
		Enclose("(", ")");
		return true;
	}
	if(code == '{') {
		Enclose("{", "}");
		return true;
	}
	if(code == '[') {
		Enclose("[", "]");
		return true;
	}
}

// MODERATOR: use code tag four source code.
-----------------------------------------------------
I am a novice programmer, and I am of the opinion that if we used [else if] statements for the 2nd and 3rd [if] cases, we would be able to save some processing power no matter how minute.
I understand that more experienced programmers like yourselves already know about this concept. That leads me to believe that this was done for some other reason. I would very much appreciate it if you would help me understand as to why this was done so that I am able to learn from you.

Thank you kindly,
Amin

[Updated on: Wed, 08 June 2022 20:56] by Moderator

Report message to a moderator

Re: Source Code Efficiency Minor Issue [message #58531 is a reply to message #58529] Wed, 08 June 2022 21:09 Go to previous messageGo to next message
Klugier is currently offline  Klugier
Messages: 1077
Registered: September 2012
Location: Poland, Kraków
Senior Contributor
Hello Amin,

Welcome on our forunm Smile

This is easy, because you have return statement within if block, so else if is redundant. The execution of if block will be break anyway. If there will be no return statement within if block, then you should use "else if" instead of "if" for performance reasons you have mentioned in your message.

Answer on stack overflow.

Klugier


U++ - one framework to rule them all.
Re: Source Code Efficiency Minor Issue [message #58532 is a reply to message #58531] Wed, 08 June 2022 23:33 Go to previous message
aminhere is currently offline  aminhere
Messages: 3
Registered: June 2022
Location: Waterloo
Junior Member
Hi,

Thank you for the prompt reply, I completely overlooked the returns!

Thank you,
Amin
Previous Topic: Know what you're using. Size of some common types.
Next Topic: U++ libraries and TheIDE converted to Meson build system
Goto Forum:
  


Current Time: Mon Jul 15 20:29:03 CEST 2024

Total time taken to generate the page: 0.01275 seconds