79,866 questions
Best practices
0
votes
4
replies
202
views
Is it safe to use public functions in C++?
I am creating a program with C++ language that working with strong cryptography.
Does it matter if I use public or private functions where contains a secret algorithms, any sensitive structures of ...
3
votes
1
answer
99
views
Powershell Class generic interface arguments type resolution problem
Can't seems to find why generic interface types are allowed in powershell class argument attributes, but they can't accept anything - powershell class type resolution doesn't work in this case. Is ...
1
vote
2
answers
89
views
JavaScript: How many objects are allocated when returning an object literal from a class constructor?
Let's say I have this code:
class MyClass {
constructor() {
return {};
}
}
const x = new MyClass(); // how many objects are instantiated with this?
I know that variable x just holds ...
0
votes
2
answers
108
views
How to break circular dependency in Python class when trying to separate a simple wrapper class from a heavier implementation?
I am trying to build a small scale deep learning framework. I defined my tensor class as follows
class Tensor:
__slots__ = (
"_backend",
"_data",
"...
3
votes
2
answers
103
views
Verbose in class with "using module" directive
I faced a specific behavior while using verbose output in class.
This works like a charm:
# SomeModule.psm1
class SomeClass {
SomeClass() {
Write-Verbose "It works!"
}
}
...
Advice
1
vote
4
replies
71
views
Add an instance to a virtual subclass?
With abstract subclasses on can use register to add other classes as a "virtual" subclass, what would be a way to do that for a single instance based on it fullfilling some criteria?
The &...
Advice
1
vote
3
replies
65
views
Creating classes/class objects in JS - perhaps jQuery, not sure
What is this?
(function (Skd, $, undefined) {
title = "SkdInternal"; // internal?
#title = "SkdPrivate"; // private?
Skd.title = "Skd"; // public?
Skd....
Best practices
0
votes
4
replies
83
views
using variable of type Class<?> in switch construct
i'm in need of a data container for several data types and fail to write some omnipotent :-) converter func.
Maybe my idea is crab, in this case please give me a hint what concept to use.
My current ...
1
vote
2
answers
168
views
Trouble with VBA Class Instantiation [closed]
I've created a VBA Class module and written all the necessary code within it. When I go to use it, in Excel, I instantiate it in a global module as follows.
Public gblFrequencyList As New clsLists
...
Advice
0
votes
4
replies
125
views
VB.NET and classes and their sub-classes
I have a class in VB.NET. The definition of this class is re-defined according to need.
For example: TR as char(2), F1 as Char(10) then later TS as Char(2) F1 as float.
I want to define one class and ...
2
votes
1
answer
116
views
In python is there a way to get len with int data type and not and index-sized integer? [duplicate]
I working on a code where it is necessary to have large integers, here is a simplified version of it (len_class.py):
class BigLen():
def __len__(self):
return 10**100
However I'm running ...
0
votes
2
answers
139
views
Create a custom method for all existing product types in WooCommerce
I want to create a custom method I can use for any WC_Product class, so I can use $product->get_lead_time(); anytime I have a product object available. I currently have it working for Simple ...
0
votes
1
answer
80
views
Automate removal of div/span attributes for code clean-up and easier merging
<span class="SpellingError SCXO166867203 BCX8" style="margin:0px;padding:0px;background-repeat:repeat-x;background-position:left bottom;">bv</span><span class="...
2
votes
1
answer
212
views
Void function doesn't print elements of matrix C++
I'm trying to print elements of matrix (example will be below). Here is the following code written in Dev-C++:
#include <iostream>
using namespace std;
class Matrix {
private:
int **...
2
votes
2
answers
123
views
Subtlety in initializing attributes with methods in modules from the `equinox` `jax` library
I have the following code that defines an abstract class and its final subclasse. The two classes are both subclasses of the equinox.Module class, which registers class attributes as the leaves of a ...
3
votes
4
answers
112
views
Why must classes be defined in order of appearance in python module?
Let's say I have a python file test.py that looks like this:
class MyFirstClass():
prop=3
class MySecondClass():
prop1 = 0.
prop2 = MyFirstClass()
Then I can run this and it works:
from ...
1
vote
3
answers
136
views
Better way to override methods on an instance of a JavaScript class
In our JavaScript web app, we use a custom-made component framework. All of our components are defined as classes using the class syntax.
We can make child classes that inherit the parents, and they ...
1
vote
1
answer
85
views
Update a class when the extended super class setter is used
I have an issue with the data within an extension class does not change when I change data within the super class.
This might be an XY issue or caused by the fact that I'm still not used to using ...
-3
votes
1
answer
114
views
How can I pass a reference to an internal class upon construction of a public-facing subclass without violating nullabe safety?
I'm not super experienced with C#, and this is a bit of a puzzle. Consider the following code:
#nullable enable
using System.Collections.Generic;
// Biology.dll
public abstract class Animal
{
...
0
votes
1
answer
86
views
One object has to work with part of data (line of an array) from another object
I'm not a professional programmer. I'm teaching my children and decided to create a solver to nonograms puzzles. The algorithm itself is not what concerns me, but the proper way to code it.
What I ...
-5
votes
1
answer
146
views
calling a class object in an iterative way on python
I made the next class
obj = MyClass()
fds=['a','b','c']
for i in fds:
attribute_name = f"{i}"
setattr(obj, attribute_name, [f"{i}"])
print(obj.i)
I know that obj.i is ...
1
vote
1
answer
152
views
Hide a class method programmatically
A while ago I wrote a small function to easily Use-ClassAccessors in PowerShell. I would like to add a new feature:
Any accessor method (in the form of get_<property name>()) will automatically ...
-4
votes
4
answers
171
views
How to update string attributes to object instances if they exist [closed]
I'm trying to use a for loop to iterate through a set of objects, check if those objects store string data (specifically their 'Pokemon.evolution' variable) which is the same as a the name of one of ...
-5
votes
2
answers
106
views
attributes in a class [closed]
I am working on an example of a class called Car. Can you help clarify the difference between the attributes after the initialization statement and those within the indentation? How is ...
0
votes
1
answer
92
views
PHP autoloading with multiple third-party libraries [closed]
I'm writing a plugin that uses a few third-party libraries (one from a long-abandoned repo that I'm modifying). Library A uses Library B, and my code uses both.
In Library A are 50-odd files with ...
0
votes
1
answer
133
views
How to determine class of an element in Javascript
I want to determine the class name of existing table TD elements (using the Chrome Javascript).
My case is table rows all like
<tr><td class="ns"><a href="a link">...
2
votes
1
answer
110
views
How to separate built-in object from user objects?
I'm trying to write a function TypeNameEx which will return a string which, using a call to VarType(), effectively identifies the type of a a (variant) variable, eg VarType 2 returns integer and ...
0
votes
1
answer
250
views
What is the actual implementation of delphi helpers?
type
TTestHelper = class helper for TStringList
procedure Test;
end;
What is the actual implementation of Delphi class helpers? In the System unit, I can find the define of TClassHelperBase. ...
2
votes
1
answer
146
views
Unsure how to create relationships between classes within python
The classes works when separate, now, I want to create relationships between them. However, this has caused issues when I am trying to define the relationships.
For example:
sqlalchemy.exc....
0
votes
2
answers
263
views
Can the dot operator path be shortened?
In C++ I have variables in classes in classes. It often results in long dot operators to get to the variable. For example:
int x = class1.class2.class3.variableName;
Would it be possible to replace ...
0
votes
2
answers
162
views
How do I make a variable declared in a class in C++
I have a variable, value, declared in a class, input. I want to use it inside main. Here is my code.
#include <iostream>
#include <fstream>
#include <chrono>
#include <thread>
#...
0
votes
1
answer
64
views
How can I forbid method redefenition in TCL OO class?
I would like that method redefenition would result in failure and script execution stop. Like any other common error.
In the following example I want to see that method print cannot be redefined.
oo::...
-7
votes
1
answer
97
views
How can I pass a class type into a method and use it to create new objects of the class? [closed]
I have a situation where I have multiple csv files that I want to transform into various objects. So I have something like:
#What works
car = []
with open("car.csv") as csv_file:
data = ...
0
votes
2
answers
171
views
How do I correctly bind to / observe a non-observable object within SwiftUI?
I have a view, TimeEditView, that edits an object of an Item class I made. The class does not conform to ObservableObject, since if it does, then it will cause issues with using GRDB.
I am currently ...
0
votes
1
answer
85
views
How to reference current property value in class property attribute in PHP 8.4?
I've done a lot of Googling and may have missed this, there's so many examples of using the new Attribute feature in PHP but none of them show if this is possible. What I would like to be able to do ...
1
vote
2
answers
73
views
Vector from Class objects vector as 2D vector function parameter
Solution requirements:
Pre C++11
Statements:
Function someFunction exists, that accepts 2D vector as vector of string vectors: vector2d.
Class someClass exists, that contains 1D vector of strings: ...
-1
votes
1
answer
108
views
Proper way to pass a class around SwiftUI views [closed]
I have a SwiftData class that I get with @Query private var items: [Item] in a SwiftUI view. Then I pass it to a sub view that passes it to other sub views. What is the best way to pass the class ...
1
vote
1
answer
67
views
In Lisp can't make-instance because :name isn't provided
This code creates an error: The slot COMMON-LISP-USER::NAME is unbound in the object
#<THING {1002B830F3}>.
I tried sbcl and clisp, both creating same problem. I can initialize instance of ash ...
-1
votes
1
answer
110
views
Why doesn’t method overriding in Python affect the base class instance?
I'm a bit confused about how method overriding works in Python.
Let's say I have a base class with a method, and I override that method in a subclass. When I call the method from the subclass, the ...
0
votes
3
answers
127
views
Minifiying javascript file with webpack breaks vue functionality (specifically with method calls on class instance)
I am working on an ASP.NET project that uses Vue.js and jQuery. I have a JavaScript file (fields.js) that defines several classes (e.g., Users, Fields) and initializes a Vue instance. When I use the ...
2
votes
1
answer
180
views
Declareing array that stores a struct, which defined in another file included, gives the error "Incomplete Type "Array[]" is not allowed"
I have defined a struct in another file called file1.h (example) and when I declare an array using that struct in another file called File2.h, i get the error Message:
"Incomplete Type "...
3
votes
1
answer
59
views
Using a class with numpy does not work correctly
I define an array of 4 corners
import numpy as np
class Corner():
centres = np.zeros((3,2))
id=0
corners=np.empty((4)).astype(Corner)
for i in range(4):
corner=Corner()
corner.id = ...
6
votes
0
answers
87
views
The memory usage of the __dict__ of instances of a class
import sys
class Vector:
def __init__(self, x, y):
self.x = x
self.y = y
v1 = Vector(1, 2)
v2 = Vector(1, 2)
print(f"v1 __dict__ : {sys.getsizeof(v1.__dict__)} bytes")
...
3
votes
1
answer
133
views
How to recursively use variadic templates with classes?
I've tried to recursively define variadic template classes, similar to various examples I saw for functions:
class Network
{
public:
template<int m>
const void forward(const Matrix<m, ...
0
votes
0
answers
64
views
PHP Class Object Shopping Cart Data Storage Problem
H I am trying to store my shopping cart variables using Classes/Objects for integration with Klarna. The following code works great on testing but I now need the Cart (products) to be dynamically ...
0
votes
0
answers
111
views
Got crash when using thread_local to describe unordered_map
I have tested the following code and the run crashed at when the map does ~_Hashtable() and clear().
This case is simplified from my project. And I do need to use thread_local to describe map. I want ...
0
votes
1
answer
78
views
Run time error related to main method error
I'm currently studying Java in general and inheritance in particular.
When I run the code below in an online editor it throws an error related to the main method, however, when I modify it as ...
0
votes
1
answer
77
views
Is it possible to reuse property code to get rid of annoying property copy/paste boilerplate in a dataclass?
This is going to be a bit hard to explain, but I'll try nevertheless:
So, I'm a novice trying to turn a Kahoot Generator I made into a library to share on GitHub. After thinking about how I wanted the ...
-1
votes
1
answer
112
views
Why doesn't javac generate a new .class file after renaming the class?
Why doesn't javac generate a new .class file after renaming the class?
My file name is Test.java.
Case #1:
class example {
public static void main() {}
}
When I compiled this using javac Test....
0
votes
3
answers
85
views
Create class instances with dictionary keys as instance name
I have a dictionary with course names and some info on each course. I want to dynamically create Courses() instances for each of the 4 courses in the dictionary. But I want to be able to reference ...