type-safety Questions
9
Solved
According to Wikipedia
Computer scientists consider a language "type-safe" if it does not allow operations or conversions that violate the rules of the type system.
Since Python runtime checks...
Pad asked 24/9, 2017 at 8:57
1
Solved
The cppref page on std::format says:
It is not an error to provide more arguments than the format string requires:
// OK, produces "Hello world!"
std::format("{} {}!", "H...
Buckeye asked 1/2 at 9:58
5
Solved
Is there a way to make C a little more aware of types and assure type-safety?
Consider this:
typedef unsigned cent_t;
typedef unsigned dollar_t;
#define DOLLAR_2_CENT(dollar) ((cent_t)(100*(dolla...
Izmir asked 1/4, 2016 at 8:24
4
Solved
I am looking for a simple way to directly convert a python dict to a custom object as follows, while not breaking intellisense. The result should not be read-only, it should behave just like a new ...
Variegated asked 9/12, 2019 at 14:6
4
Solved
Having this example:
interface Event {
title:string;
description:string;
fromDate: Date;
toDate: Date;
location: {
name: string;
lat: number;
long: number;
}
}
Using a type something like...
Subpoena asked 22/3, 2021 at 17:39
2
Solved
I've been reading Head First Object-Oriented Analysis and Design book and I'm trying to learn oop.
in one of the pages of this book, I've read these lines:
we’ve made the application less fragile ...
Pneumato asked 21/8, 2023 at 7:2
17
Solved
[Note: This question had the original title "C (ish) style union in C#"
but as Jeff's comment informed me, apparently this structure is called a 'discriminated union']
Excuse the verbosit...
Stillborn asked 30/6, 2010 at 17:18
2
Since TypeScript 3.0 introduced the unknown top type in mid-2018, use of the any type is discouraged.
TypeScript also had had long support for succint type-guards with the typeof operator, but typ...
Bergeron asked 16/2, 2021 at 6:1
2
Solved
Is there a substantial difference between the AppSettingsReader class and the AppSettings member of the ConfigurationManager class in .Net 3.5?
I'm building out some legacy code and a previous dev...
Potomac asked 16/8, 2010 at 22:3
1
Solved
I wonder if there is an alternative way to specify the function type "any function" that does not use any (and therefore improves type-safety).
To clarify, I am searching for an alternati...
Siding asked 3/3, 2023 at 17:3
3
Solved
Let's have the following two interfaces:
interface A {
foo: string;
bar: number;
}
interface B {
foo: string;
}
How can I type-safely convert an object that conforms to A to one that conforms ...
Branching asked 31/1, 2023 at 15:8
1
Solved
I've got a function with a generic that is a tuple of 1 or a tuple of 2 elements.
I want to ensure that all properties used in the function use the same length tuple.
type TypeA = [string] // Tuple...
Undershorts asked 25/1, 2023 at 12:16
13
What does "type-safe" mean?
Shelving asked 4/11, 2008 at 2:27
4
Solved
Can I refer to angular component class as a type? I see Ionic uses any for components. Is it possible in Typescript to declare an argument type, that expects only component classes?
I saw this que...
Phaih asked 22/8, 2017 at 17:7
5
Solved
In Typescript you can declare that all elements in an array are of the same type like this:
const theArray: MyInterface[]
Is there anything similar you can do that declares that ALL of an object...
Autosuggestion asked 9/7, 2018 at 2:48
9
Solved
Is there a way to enforce/limit the types that are passed to primitives? (bool, int, string, etc.)
Now, I know you can limit the generic type parameter to a type or interface implementation via the...
Vashti asked 12/8, 2008 at 15:7
9
Solved
Also, does one imply the other?
Beatific asked 22/4, 2010 at 12:2
2
Solved
I have a pointer T * pValues that I would like to view as a T (&values)[N]
In this SO answer https://stackoverflow.com/a/2634994/239916, the proposed way of doing this is
T (&values)[N] = *...
Osculate asked 23/1, 2014 at 19:3
10
Solved
Does it make sens in C++ to define physics units as separate types and define valid operations between those types?
Is there any advantage in introducing a lot of types and a lot of operator overl...
Protective asked 11/11, 2013 at 16:12
1
Solved
In Scala 3, let's say I have a List[Try[String]]. Can I split it up into success and failures, such that each list has the appropriate subtype?
If I do the following:
import scala.util.{Try, Succes...
Ferule asked 7/10, 2021 at 14:58
3
Solved
The number is a very loose representation which sometimes is required to be tighten. In my case I wish a variable was only able to take non-negative integers. Is there a way to enforce this constra...
Crake asked 20/1, 2014 at 1:30
5
Solved
Assume I'm doing some socket programming:
struct sockaddr_in sa;
inet_pton(AF_INET, "127.0.0.1", &(sa.sin_addr));
auto *resa = reinterpret_cast<struct sockaddr*>(&sa);
bind(sfd, resa...
Poling asked 27/5, 2017 at 20:37
1
Solved
Consider the following simple example involving Aux-pattern:
sealed trait AdtBase
abstract case class Foo(){
type T <: AdtBase
}
object Foo{
type Aux[TT] = Foo { type T = TT }
}
abstract ca...
Beanpole asked 4/11, 2020 at 1:5
3
Solved
I'm writing a type-safe code and want to replace apply() generated for case classes with my own implementation. Here it is:
import shapeless._
sealed trait Data
case object Remote extends Data
cas...
Heterolysis asked 20/10, 2020 at 21:10
8
When I wish to bind a control to a property of my object, I have to provide the name of the property as a string. This is not very good because:
If the property is removed or renamed, then I don’...
Bonne asked 25/8, 2009 at 15:44
1 Next >
© 2022 - 2024 — McMap. All rights reserved.