questionable | Question your objects | Machine Learning library
kandi X-RAY | questionable Summary
kandi X-RAY | questionable Summary
Question your objects
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of questionable
questionable Key Features
questionable Examples and Code Snippets
Community Discussions
Trending Discussions on questionable
QUESTION
I would like to know what would be a good approach, from a software design standpoint, to a situation where each derived class should have a different type of polymorphic data member. In more detail:
I'm writing a library that has an abstract base class Base
that users of the library will inherit from. for one member of Base
, let's call it BaseMember
, I want polymorphic behavior. What I mean by that is that various classes derived from Base
will "contain" different subclasses of BaseMember
- some will contain a OneDerivedMember
, others will contain AnotherDerivedMember
etc (all of these are derived from BaseMember
, and all are supplied in the library). The reason for wanting that, is that I want to be able to go over some collection of Base
pointers and activate some functionality of BaseMember
(which is implemented differently for its different derived classes). As I understand it, I am guessing I have to make BaseMember
a pointer. Now my questions start:
- First of all, is all of this even a good approach or do you sense a "code smell" here? Is building it like that a common practice?
Assuming the basic approach is OK:
Where would be the proper location to allocate the
BaseMember
pointer? in the constructors of the various derived classes?Can I enforce that the derived classes actually do this allocation? i.e. what if a user didn't understand, or forget, that they needed to allocate one kind or other of
SomeDerivedMember
and make theBaseMember
pointer point to it? How can I force it not to compile in such a case?Where should this member be released (de-allocated)? I suppose the RAII approach dictates it would be in the same scope it was allocated in (so, destructor of derived class?) but this forces every user of the library to remember to do this de-allocation. Instead, I could do it in the destructor of
Base
(i.e. in the library, not by the user) - but would this violate the RAII principle? and what if the user DID decide to de-allocate it (double delete...)?Alternatively to all this, can you imagine a way to have equivalent polymorphic behavior without even using dynamic allocation? This code is for a low-level embedded MCU, Cortex M4 or similar cores and bare metal (no OS) - so I try to stay away from dynamic allocation wherever possible.
I feel this kind of situation must be be fairly common, and there would be a design pattern that solves this cleanly, however I'm not sure what that would be.
Example code:
...ANSWER
Answered 2021-May-31 at 09:24EDIT Following the suggestions of the OP, I replaced the example with a fully runnable one
I would make the interface difficult to be misused:
QUESTION
The title is probably poorly worded, but I'm trying my hand at creating a REST api with symfony. I've studied a few public api's to get a feel for it, and a common principle seems to be dealing with a single resource path at a time. However, the data I'm working with has a lot of levels (7-8), and each level is only guaranteed to be unique under its parent (the whole path makes a composite key).
In this structure, I'd like to get all children resources from all or several parents. I know about filtering data using the queryParam at the end of a URI, but it seems like specifying the parent id(s) as an array is better.
As an example, let's say I have companies in my database, which own routers, which delegate traffic for some number of devices. The REST URI to get all devices for a router might look like this:
...ANSWER
Answered 2021-May-20 at 04:02However, I am new to all of this and having trouble finding what is "standard". Is this a reasonable solution?
TL;DR: yes, it's fine.
You would probably see an identifier like that described using a level 4 URI Template, with your list of identifiers encoded via a path segment expansion.
Your example template might look something like:
QUESTION
Setting aside all the concerns about the necessity of using typeid
and dynamic_cast
and their questionable effects on code maintenance, is there any information about the performance of these two dynamic type introspection mechanisms? The Wikipedia article on RTTI claims that:
The use of typeid, in a non-polymorphic context, is often preferred over dynamic_cast in situations where just the class information is needed, because typeid is always a constant-time procedure, whereas dynamic_cast may need to traverse the class derivation lattice of its argument at runtime.
However no citation is provided. As such I wanted to ask if this claim is true and if one of these two mechanisms should definitely be preferred performance-wise over the other. I wasn't able to find information about any bounds on time complexity of these operations.
...ANSWER
Answered 2021-May-17 at 17:57The language standard doesn't impose any requirements about the complexity of either operation. As such, the statement that you quote isn't backed up by specification. It is presumably based on either how the functionality can be, or has been implemented in practice.
Bigger problem with the claim of preferability is that it is quite unclear how dynamic_cast
even could be used in a non-polymorphic context.
If you're doing object oriented dynamic polymorphism, then what you should prefer is virtual functions.
QUESTION
I'm learning swift, and I do the sololearn course to get some knowledge, but I bumped into something that I don't understand.
It is about modifying an array's values. The questionable part states the following:
...In the following example, the elements with index 1, 2, 3 are replaced with two new values.
ANSWER
Answered 2021-May-13 at 18:27You could use a tuple (Value, Value), or create a struct
to handle your values there, in fact if you plan to reuse this pair or value, a struct
is the way to go.
By the way, there's no need to add [1..3]
, just put the values inside the brackets.
QUESTION
I'm working on WebRTC streaming which streams video from a device to a browser. This streaming works in Chromium browsers just fine but fails in Firefox. There is a failure with the SDP exchange which then halts the rest of the connection (no ICE candidates sent after SDP exchange).
There are some issues with Firefox's answer SDP I've found but I haven't discovered a reason for the issues: SDP mentions VP8 but we use H264 only; m=video 0 has port 0 but typically that's non zero; I typically get an a=inactive line; a=sendrecv should probably be a=recvonly; many other lines are missing (for example, ICE-specific lines)
SDP examples below:
...ANSWER
Answered 2021-May-13 at 18:03Firefox likely doesn't support the profile level id 0x4d4016. Then you have no codecs in common and the media is rejected (which is what port 0 means). Without any non-rejected m-line your connection will fail.
QUESTION
We have a legacy application that uses SQL Server as its back-end. As part of some security concerns, it encrypts some fields collected from the user using (single) DES with a key & IV that is hard-coded into the app code, then Base64 encodes the encrypted bytes, and finally stores that string in a varchar column in the DB. Woefully insecure at this point (and probably when it was first coded), along with a questionable design / implementation, but it is what it is. My task is to implement a CLR User Defined Scalar Function in SQL Server that can decrypt this type of data.
As a proof of concept, I created the following short console app to make sure I understand the DES decryption process in C#:
...ANSWER
Answered 2021-May-07 at 20:13After reproducing your results in both places and changing several things yet not changing the output, I went over both sets of code making sure they were the same and found the issue:
In the call to new CryptoStream()
, you are using des.CreateDecryptor(Key, IV)
in the console app (correct), but using des.CreateEncryptor(Key, IV)
in the SQLCLR function (different and incorrect). Changing the SQLCLR function to instead use des.CreateDecryptor(Key, IV)
results in the expected output.
Some general notes regarding the code:
- You should use the
Value
property of theSql*
types (i.e. the input parameters) instead of callingToString()
or casting. For example:
QUESTION
I have following piece of code:
...ANSWER
Answered 2021-Apr-07 at 06:30You read a partly uninitialized struct object to return it, which is (arguably) Undefined Behaviour on the spot, even if the caller doesn't use the return value.
The 16-byte struct is returned in RDX:RAX in the x86-64 System V ABI (any larger and it would be returned by having the caller pass a pointer to a return-value object). GCC is zeroing the uninitialized parts, clang is leaving whatever garbage was there.
GCC loves to break dependencies any time there might be a risk of coupling a false dependency into something. (e.g. pxor xmm0,xmm0
before using the badly-designed cvtsi2sd xmm0, eax
). Clang is more "aggressive" in leaving that out, sometimes even when there's only a tiny code-size benefit for doing so, e.g. using mov al, 1
instead of mov eax,1
, or mov al, [rdi]
instead of movzx eax, byte ptr [rdi]
)
The simplest form of what you're seeing is returning an uninitialized plain int
,
same difference between GCC and clang code-gen:
QUESTION
Currently I am pulling data from an API that is in JSON format. I parse this dataframe using ‘json.loads’ into a python variable, where I then upload this data to a connecting MYSQL database.
The issue I am encountering is that the JSON data stored in ‘employeed_parsed’ as detailed below, has a chance of incorrect data coming through.
...ANSWER
Answered 2021-May-04 at 06:05If I understood your question correctly, you are trying to clean up the emp_data
list by removing observation dictionaries whose "Good" value is false. There are multiple ways to do this, a simple one would be:
emp_data_cleaned = [observation for observation in emp_data if observation["Good"]]
Alternatively, you could use the filter
function, which might be more efficient if you don't want to compute the result right away:
emp_data_cleaned = filter(lambda observation: observation["Good"], emp_data)
QUESTION
I am building a website (related to my homework! which has a javascript code containing three characters, their description, and the number of comments related to them. So far, only one character is visible on the webpage which is "Finn the Human"
What I want to achieve is to have 3 boxes display next to each other with the name/description of the rest of the characters.
How it's supposed to look like
It's a type of homework, we need to create those two boxes using the for each cycle in JavaScript. Any ideas on how to do this?
...ANSWER
Answered 2021-Apr-23 at 12:01getElementsByClassName
returns an node list not element, thats what console error was showing. You have two rows, so target first one from list with[0]
:.getElementsByClassName('row')[0]
you need to create new elements on the fly for each object in loop so move that creation inside loop.
you are not accessing your object data at all to insert it into created elements. Use
character.wat
andcharacter.who
Also research this very useful tool: insertAdjacentElement
QUESTION
I want to convert a bool
into an int
. The "standard" option is:
ANSWER
Answered 2021-Apr-07 at 12:05In a system where the conversion could have an impact the most efficient way is to not convert and to keep trues and falses as target type (int
or byte
, etc.).
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install questionable
On a UNIX-like operating system, using your system’s package manager is easiest. However, the packaged Ruby version may not be the newest one. There is also an installer for Windows. Managers help you to switch between multiple Ruby versions on your system. Installers can be used to install a specific or multiple Ruby versions. Please refer ruby-lang.org for more information.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page