8 Replies - 663 Views - Last Post: 15 April 2017 - 12:02 PM

#1 Taglialegna  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 08-April 17

Personal utility library

Posted 08 April 2017 - 05:22 AM

I've tried to make a library with functions which help everyday programming and I want to share it.

Link to github: https://github.com/T...NSU-Library-cpp

If you want, you can give your opinion on this.
Is This A Good Question/Topic? 0
  • +

Replies To: Personal utility library

#2 Spigie  Icon User is offline

  • New D.I.C Head

Reputation: 7
  • View blog
  • Posts: 18
  • Joined: 05-April 17

Re: Personal utility library

Posted 08 April 2017 - 05:36 AM

Some of these look very useful. But I have one question about the way it's structured.
Why is everything thrown into one file? Wouldn't it be better if you had different categories for different types of functions? For example "MSU_Math" and "NSU_Conversion", that would also make it easier to expand on later on, and to not have to include a bunch of overhead if you're only going to be using only one of the categories.

Other than that, good job, it looks good! :D
Was This Post Helpful? 0
  • +
  • -

#3 Taglialegna  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 08-April 17

Re: Personal utility library

Posted 08 April 2017 - 06:04 AM

Well, actually I haven't planned how to structure it, I just wrote it down. Certainly at one point I would have split it in various sections. I'll divide it in many files. Thank you!!

This post has been edited by Skydiver: 09 April 2017 - 07:52 PM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5885
  • View blog
  • Posts: 20,092
  • Joined: 05-May 12

Re: Personal utility library

Posted 09 April 2017 - 07:52 PM

Taglialegna: There is no need to quote the post above yours. Just use the big Reply button or the Fast Reply area.
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5885
  • View blog
  • Posts: 20,092
  • Joined: 05-May 12

Re: Personal utility library

Posted 09 April 2017 - 08:01 PM

Unlike Spigie, I'd question the correctness and utility of some of the functions you are providing.

	std::vector<int_fast64_t> IntToStr (int_fast64_t intNumber){
		std::vector<int_fast64_t> strNumber;
		for(unsigned i = 0; intNumber != 0; i++, intNumber/=10){
			strNumber.push_back(intNumber%10);
		}
		return strNumber;
	}



Really? How is a vector of integers a string in the C++ sense of the word? Even if used the classic assembly programming definition of the word string instead of the C or C++ sense of the word (e.g. the classic definition of a string back then was an series of things of the same type), your implementation is still broken because it returns the digit of the integer in reverse order. To make matters worse, how are you dealing with an integer value of 0? How are you dealing with negative integers?
Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5885
  • View blog
  • Posts: 20,092
  • Joined: 05-May 12

Re: Personal utility library

Posted 09 April 2017 - 08:13 PM

	int_fast64_t IntToBin(int_fast64_t IntNumber){
		int_fast64_t binNumber = 0;

		for(unsigned i = 1; IntNumber != 0; i *= 10, IntNumber/=2){
			binNumber += IntNumber%2*i;
		}

		return binNumber;
	}



Computers already store integers in binary. Why are you returning another integer? Shouldn't you be returning a vector of bits or a string of 0's and 1's?

void lin_prop(double& value, double var, double low_bound, double up_bound, double min_value, double max_value){
		value = ((var - min_value)*(up_bound - low_bound)/(max_value - min_value)) + low_bound;
	}



Why is value even a parameter? Why can't the computed value just be returned by the function?
Was This Post Helpful? 0
  • +
  • -

#7 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5885
  • View blog
  • Posts: 20,092
  • Joined: 05-May 12

Re: Personal utility library

Posted 09 April 2017 - 08:20 PM

void normalize(std::vector<double>& container){
		auto record = *std::max_element(container.begin(), container.end());
		for (auto&& i : container){
			lin_prop(i, i, 0.0, 1.0, 0.0, record);
			//the function uses the address of the value to change the value itself
		}
	}



This code incorrectly assumes that lowest value inside the container is going to be 0.0. This code can also be improved to accept iterators instead of forcing the use std::vector<>. That way it can support any type of STL container. It can further be tweaked to not be hard coded to be using double, but rather any type that supports basic math operations. Also, if lin_prop() was fixed to return a value as I mentioned earlier, then the need for the comment line goes away because the code becomes self-evident.
Was This Post Helpful? 0
  • +
  • -

#8 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5885
  • View blog
  • Posts: 20,092
  • Joined: 05-May 12

Re: Personal utility library

Posted 10 April 2017 - 07:46 AM

On further reading of that normalize() function, performance can be much improved by computing the scale factor outside of the loop since that remains constant throughout the loop. Multiplication and division is expensive (yes, even with modern math co-processors), so you'll want to minimize the number of times you perform those operations.
Was This Post Helpful? 0
  • +
  • -

#9 ndc85430  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 587
  • View blog
  • Posts: 2,466
  • Joined: 13-June 14

Re: Personal utility library

Posted 15 April 2017 - 12:02 PM

Why is the changeState() function necessary? Why wouldn't one just write !b for some boolean variable b?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1