Questions tagged [type-conversion]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
95 views

Should I use method overloading or method overriding when creating converter service

In a Java Spring API, I'm implementing GeoJson Conversion Service to convert different types to geojson, I have GeoJsonConversionService interface, and one implementation is ...
zyydoosh's user avatar
  • 103
-1 votes
1 answer
161 views

Conversion methods: from_xxx() or to_xxx(), is there a reason I shouldn't stick with to_xxx()?

I have a C++ library that I'm converting to Python. In the C++ library I have multiple constructors and many different types of conversion functions (think radians to degrees, and different types of ...
Krupip's user avatar
  • 1,252
6 votes
1 answer
400 views

Too many conversion between layers

I'm developing a back-end application and I ran into the problem of too many conversions between layers. For a single type it is like this: So every time I update the model, I need to update six ...
Yola's user avatar
  • 191
2 votes
2 answers
162 views

Primitive type conversion in computer graphics

I have been repeatedly told that explicit type conversions are an indicator of bad code and they should be avoided. Now in all honesty I have been annoyed a bit by these claims due to the nature of ...
Makogan's user avatar
  • 261
0 votes
2 answers
438 views

Formatting a string by converting to a number then back to a string

I'm not sure whether this qualifies as code smell, or if there may be some better way of performing the same task, but, basically, I want to format a 10 digit string, using C#, and have the following ...
Paul's user avatar
  • 201
5 votes
3 answers
140 views

Create a single class to map different object to a target object?

I have a service (S) that receives an object of type 's', this service will be called by several classes (maybe 6) and each class has their own object a,b,c, etc. with the information necessary to ...
joe's user avatar
  • 61
0 votes
1 answer
110 views

Implicit conversion for function subtyping

Languages with coercions (i.e. implicit type conversions) allows expressing things like that (irrespective of any syntax): f : int32 → int32 = λx.x+x a : int16 = 42 b : int64 = f(a) Where type ...
cuihtlauac's user avatar
4 votes
1 answer
103 views

Converting Interfaces to Sub types. Is this bad SE?

In the company I work for, I keep seeing IManager interfaces being converted into their real types and lots of "instanceof / TypeOf" if statement checks. For example: IManager manager // passed to ...
Mayron's user avatar
  • 181
2 votes
1 answer
91 views

Does an explicit temporary of an integral type qualify as an integral constant expression?

In the following code, int() is an explicit type conversion. #include <iostream> int main() { void* ptr = int(); return 0; } Clang Compiler: source_file.cpp:5:11: error: cannot ...
Jemes's user avatar
  • 133
3 votes
1 answer
194 views

Naming a view class

I'm a little hesitant on what to name a view class. I have a view class which I call ChooseImageView because that's what the user does in that view. After the user has chosen an image I display a ...
Peter Warbo's user avatar
3 votes
3 answers
23k views

Best place to convert one object to another object

I'm writing an interface to bundle two underlying APIs into one new. The APIs provide data about archived invoices. All three APIs (the two old ones and my new one) have different data structures. ...
das Keks's user avatar
  • 203
7 votes
2 answers
17k views

Why can't C# implicitly convert int to string?

C# allows implicit conversions of integers to strings when used in an expression. For example, this is completely valid: int myInt = 10; string concatenatedString = "myInt is " + myInt; string ...
Jacob Stamm's user avatar
1 vote
2 answers
880 views

Different Number Base Systems

I am doing a summer assignment for AP Computer Science. For this I am learning about different number base systems and how to convert them. These topics led to me wondering about why programmers use ...
Rishi Kavikondala's user avatar
10 votes
2 answers
722 views

Is it bad to create classes whose sole purpose is to be converted to another class implicitly?

Imagine a situation where we're using a library that allows you to create Circle objects, where you can specify the radius and the center of the circle to define it. However, for some reason, it also ...
user3002473's user avatar
3 votes
3 answers
341 views

Handling Value Unit data

We have some data that is strongly bound to each other and we are using it for calculations. Its a value with a unit type and an optional relation. E.g. 1500 meter above sea level. The unit type ...
Picard's user avatar
  • 133
22 votes
4 answers
26k views

Best practices regarding type mapping and extension methods

I want to ask some questions about best practices regarding mapping types and using extension methods in C#. I know this topic has been discussed multiple times over past few years, but I've read a ...
emsi's user avatar
  • 323
3 votes
2 answers
5k views

Haskell: Is it possible to convert a Num to a Float?

I need to be able to convert generic numbers (instances of Num) to a Float. I searched Hoogle for a function with the signature Num n => n -> Float, but I couldn't find any such functions (...
Carcigenicate's user avatar
0 votes
3 answers
33k views

Integer conversion with Console.ReadLine() [closed]

To read an integer from user input, you can use: int number = Convert.ToInt32(Console.ReadLine()); But why won't the following work? int number = (int) Console.ReadLine(); What's the difference ...
Dan's user avatar
  • 161
14 votes
9 answers
7k views

Why can't there be any implicit conversions?

As I understand it, implicit conversions can cause errors. But that doesn't make sense -- shouldn't normal conversions also cause errors, then? Why not have len(100) work by the language ...
Quelklef's user avatar
  • 275
0 votes
1 answer
868 views

Converting from byte[ ] to user defined type

I am working on a network simulator designed in java with the basic function of routing messages through a network. I am trying to take a Message object, encrypt it using an encryption utility that ...
Hashtag's user avatar
  • 103
0 votes
0 answers
57 views

Manual repetitive conversion between file types

Let's say i have an interest in file conversions, but everything should be made by hand and i have multiple output formats (say: csv and excel). Once i get contacted by a client, i have to link ...
NicoJuicy's user avatar
  • 228
0 votes
2 answers
320 views

Interface (contract), Generics (universality), and extension methods (ease of use). Is it a right design?

I'm trying to design a simple conversion framework based on these requirements: All developers should follow a predefined set of rules to convert from the source entity to the target entity Some ...
Saeed Neamati's user avatar
10 votes
3 answers
8k views

C/C++: Which conversion warnings make sense in practice?

C/C++ implicit conversions can cause bugs. Here's one example: int foo, bar; scanf("%d", &foo); scanf("%d", &bar); float foobar = foo / bar; If I input 7 and 2, it's not 3.5 as expected - it'...
futlib's user avatar
  • 2,107
2 votes
6 answers
29k views

Converting an empty string to a number [closed]

If you are designing a function which should conver a string to an integer, how would you convert an empty string? The question is only about this one particular input value (empty string). Between ...
Kolyunya's user avatar
  • 955
10 votes
3 answers
8k views

Is relying on implicit argument conversion considered dangerous?

C++ has a feature (I cannot figure out the proper name of it), that automatically calls matching constructors of parameter types if the argument types are not the expected ones. A very basic example ...
futlib's user avatar
  • 2,107
60 votes
3 answers
96k views

What is the name of ** in python?

When programming Python I sometimes do a ** to make a conversion. I understand what it does but what data structures am I manipulating? A dict and what is the other? An array? Is there a name for the *...
Niklas Rosencrantz's user avatar
7 votes
4 answers
2k views

The need for Explicit Type Conversion in C#

Consider the following code: DerivedClass drbObj = (DerivedClass)obj; Here obj is of type Object and this is reasonable since Object is the base type of every Class in C#. Here, since the type of ...
Shamim Hafiz - MSFT's user avatar
3 votes
3 answers
2k views

What is the accepted best practice for Java type conversions?

What is the current best practice for all the type conversions necessary in a Java web application? For example, HttpServletRequest.getParameters(...) returns String[], but Hibernate does not allow ...
kevin cline's user avatar
  • 33.6k