text stringlengths 1 2.12k | source dict |
|---|---|
python, beginner, python-3.x, programming-challenge, rock-paper-scissors
Prefer:
while not win:
When you have a boolean variable, like win,
there's usually little need to explicitly compare it to True or False.
canonicalize
if player1_Choice.lower() == player2_Choice.lower() and player1_Choice.lower() in ... | {
"domain": "codereview.stackexchange",
"id": 45401,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python, beginner, python-3.x, programming-challenge, rock-paper-scissors",
"u... |
beginner, performance, c, caesar-cipher
Title: ROT13 algorithm in C
Question: I am trying to learn C and I came across the ROT13 scrambling system used to store some passwords.
Assuming the user types everything in correctly (uses 1 argument, uses a string not an int, etc.) would this be correct/safe to use? Or is th... | {
"domain": "codereview.stackexchange",
"id": 45402,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "beginner, performance, c, caesar-cipher",
"url": null
} |
bash, concurrency
Title: Blocking lock for dpkg
Question: My deployment and configuration process entails multiple processes trying to invoke dpkg on my VM at the same time. While dpkg has a locking mechanism, it causes anyone not holding the lock who is trying to acquire it to fail, as opposed to blocking.
I want bl... | {
"domain": "codereview.stackexchange",
"id": 45403,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "bash, concurrency",
"url": null
} |
bash, concurrency
# Create the lock file if it doesn't exist
touch $LOCKFILE
# Check if the lock is already held by an ancestor of this process
lock_pid=$(cat $LOCKFILE)
if ! is_ancestor "$lock_pid" $$; then
# Acquire an exclusive lock
echo "*** Process $$ trying to acquire dpkg lock" >&2
flock -x $LOCK_FD
ec... | {
"domain": "codereview.stackexchange",
"id": 45403,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "bash, concurrency",
"url": null
} |
bash, concurrency
nit: Please routinely quote such variable interpolations.
Yes, I know, in this case there's no whitespace so it doesn't matter
that it doesn't lint clean.
is_ancestor
This seems nice and I imagine it works correctly,
modulo certain assumptions about how PIDs come and go on a running system.
It is cer... | {
"domain": "codereview.stackexchange",
"id": 45403,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "bash, concurrency",
"url": null
} |
bash, concurrency
alternate design
A daemon is always doing tail -f on an install request file, or named pipe.
We replace /usr/bin/dpkg with a simple script which >> appends PID
plus the command (dpkg-exec -i baz-dev) to that file.
Optionally it verifies the daemon is running,
starting a new background daemon if need ... | {
"domain": "codereview.stackexchange",
"id": 45403,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "bash, concurrency",
"url": null
} |
python, type-hinting
Title: Postel’s law implementation with number.Complex as example
Question: I’m trying to implement, for educational purposes only, an example of the Postel’s law on a demonstrative function.
This function is not for production code, it’s for pedagogical purposes only and might be considered as a... | {
"domain": "codereview.stackexchange",
"id": 45404,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python, type-hinting",
"url": null
} |
python, type-hinting
Decades ago, when Postel worked at ISI, I was a big fan of Robustness.
But after {supporting, diagnosing, designing} systems implementing
protocols like DNS, RIP, OSPF, BGP, FTP, SMTP, and HTTP(S), plus
documents they transport, I find the principle can get in the way
just as much as it helps.
If ... | {
"domain": "codereview.stackexchange",
"id": 45404,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python, type-hinting",
"url": null
} |
python, type-hinting
review
signature
def update_prices(
prices: typing.Iterable[numbers.Complex], ...
This signature doesn't read smoothly.
And since it was constructed for didactic purposes,
readability is one of its principle goals.
Prefer:
from numbers import Complex
from typing import Iterable
def update_p... | {
"domain": "codereview.stackexchange",
"id": 45404,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python, type-hinting",
"url": null
} |
python, type-hinting
requirements document
internal documentation
test suite
We can skimp on those and get away with it, sometimes.
But it's not a sure thing.
is [Number] better than Complex or Real?
No.
When authoring a function, only make promises you can keep.
That is, promises which you have already verified, i... | {
"domain": "codereview.stackexchange",
"id": 45404,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python, type-hinting",
"url": null
} |
c++, algorithm, recursion, c++20
Title: recursive_any_of and recursive_none_of Template Functions Implementation in C++
Question: This is a follow-up question for A recursive_all_of Template Function Implementation in C++ and A recursive_count_if Function For Various Type Arbitrary Nested Iterable Implementation in C... | {
"domain": "codereview.stackexchange",
"id": 45405,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, algorithm, recursion, c++20",
"url": null
} |
c++, algorithm, recursion, c++20
template<class...Ts1, template<class...>class Container1, typename... Ts>
struct recursive_unwrap_type<1, Container1<Ts1...>, Ts...>
{
using type = std::ranges::range_value_t<Container1<Ts1...>>;
};
template<std::size_t unwrap_level, class...Ts1, template<class...>class Container1... | {
"domain": "codereview.stackexchange",
"id": 45405,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, algorithm, recursion, c++20",
"url": null
} |
c++, algorithm, recursion, c++20
template<std::size_t unwrap_level, typename F, class...Ts1, template<class...>class Container1, typename... Ts>
requires ( std::ranges::input_range<Container1<Ts1...>> &&
requires { typename recursive_variadic_invoke_result<
unwrap_level... | {
"domain": "codereview.stackexchange",
"id": 45405,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, algorithm, recursion, c++20",
"url": null
} |
c++, algorithm, recursion, c++20
template< std::size_t unwrap_level,
typename F,
template<class, std::size_t> class Container,
typename T,
std::size_t N>
requires ( std::ranges::input_range<Container<T, N>> &&
requires { typename recursive_array_invoke_re... | {
"domain": "codereview.stackexchange",
"id": 45405,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, algorithm, recursion, c++20",
"url": null
} |
c++, algorithm, recursion, c++20
template<std::size_t unwrap_level, template<class, std::size_t> class Container,
typename T,
std::size_t N>
requires ( std::ranges::input_range<Container<T, N>> &&
requires { typename recursive_array_unwrap_type<
... | {
"domain": "codereview.stackexchange",
"id": 45405,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, algorithm, recursion, c++20",
"url": null
} |
c++, algorithm, recursion, c++20
// recursive_depth function implementation with target type
template<typename T_Base, typename T>
constexpr std::size_t recursive_depth()
{
return std::size_t{0};
}
template<typename T_Base, std::ranges::input_range Range>
requires (!std::same_as<Range, T_Base>)
constexpr std::si... | {
"domain": "codereview.stackexchange",
"id": 45405,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, algorithm, recursion, c++20",
"url": null
} |
c++, algorithm, recursion, c++20
template<class T, class Proj = std::identity, class F>
constexpr auto recursive_reverse_foreach_all(T& inputRange, F f, Proj proj = {})
{
impl::recursive_for_each_state state(std::move(f), std::move(proj));
impl::recursive_reverse_foreach_all(inputRange, state);
return std:... | {
"domain": "codereview.stackexchange",
"id": 45405,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, algorithm, recursion, c++20",
"url": null
} |
c++, algorithm, recursion, c++20
template<std::size_t unwrap_level, class T, class Pred>
requires(unwrap_level <= recursive_depth<T>())
constexpr auto recursive_count_if(const T& input, const Pred& predicate)
{
if constexpr (unwrap_level > 0)
{
return std::transform_reduce(std::ranges::cbegin(input), s... | {
"domain": "codereview.stackexchange",
"id": 45405,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, algorithm, recursion, c++20",
"url": null
} |
c++, algorithm, recursion, c++20
template<std::ranges::input_range T>
constexpr auto recursive_print(const T& input, const int level = 0)
{
T output = input;
std::cout << std::string(level, ' ') << "Level " << level << ":" << std::endl;
std::transform(input.cbegin(), input.cend(), output.begin(),
... | {
"domain": "codereview.stackexchange",
"id": 45405,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, algorithm, recursion, c++20",
"url": null
} |
c++, algorithm, recursion, c++20
int main()
{
auto start = std::chrono::system_clock::now();
recursive_any_of_tests();
recursive_none_of_tests();
auto end = std::chrono::system_clock::now();
std::chrono::duration<double> elapsed_seconds = end - start;
std::time_t end_time = std::chrono::system_... | {
"domain": "codereview.stackexchange",
"id": 45405,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, algorithm, recursion, c++20",
"url": null
} |
c++, algorithm, recursion, c++20
Answer: This implementation is not short-circuiting
The standard library's std::any_of() and std::none_of() are short-circuiting: they stop iterating as soon as they know the answer. So for both std::any_of() and std::none_of(), it stops at the first position where the predicate return... | {
"domain": "codereview.stackexchange",
"id": 45405,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, algorithm, recursion, c++20",
"url": null
} |
c++, performance, api, symbolic-math
Title: Small Automatic Differentiation Library
Question: Introduction
As a programming exercise I recently wrote this automatic differentiation library based on forward accumulation. It should offer a simple way to create mathematical functions whose directional derivatives can ... | {
"domain": "codereview.stackexchange",
"id": 45406,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, performance, api, symbolic-math",
"url": null
} |
c++, performance, api, symbolic-math
#include <memory>
#include <vector>
namespace mx
{
class SField;
class Var;
namespace IMPLEMENTATION
{
class Node;
class VarNode;
class ConstNode;
class UnOp;
class BinOp;
class BaseUnOp;
class BaseBinOp;
... | {
"domain": "codereview.stackexchange",
"id": 45406,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, performance, api, symbolic-math",
"url": null
} |
c++, performance, api, symbolic-math
namespace IMPLEMENTATION
{
class Node
{
public:
mutable double value;
virtual double eval() const = 0;
virtual double derive() const = 0;
};
class VarNode : public Node
{
public:
... | {
"domain": "codereview.stackexchange",
"id": 45406,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, performance, api, symbolic-math",
"url": null
} |
c++, performance, api, symbolic-math
class BaseBinOp
{
typedef double fn(const double&, const double&);
private:
const fn* f;
public:
BaseBinOp() = delete;
BaseBinOp(fn* fun, fn* x_deriv, fn* y_deriv) : f(fun), dfdx(x_deriv), dfdy(y_deriv){}
... | {
"domain": "codereview.stackexchange",
"id": 45406,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, performance, api, symbolic-math",
"url": null
} |
c++, performance, api, symbolic-math
double b_sqrt (const double& x);
double b_sqrt_del (const double& x);
constexpr double b_negate (const double& x);
constexpr double b_negate_del (const double& x);
double b_sin (const double& x);
double b_cos (const double& x);
dou... | {
"domain": "codereview.stackexchange",
"id": 45406,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, performance, api, symbolic-math",
"url": null
} |
c++, performance, api, symbolic-math
autodiff.cpp
#include "autodiff.h"
#include <cmath>
#include <cassert>
namespace mx
{
///////////////////////////////////////////////////////////////////////////////////////////////
//SFIELD//////////////////////////////////////////////////////////////////////////////////... | {
"domain": "codereview.stackexchange",
"id": 45406,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, performance, api, symbolic-math",
"url": null
} |
c++, performance, api, symbolic-math
for (unsigned i = 0; i != N; ++i)
{
var_ptrs[i]->vn->value = position[i];
var_ptrs[i]->vn->value_dot = 0.0;
}
var_ptr.vn->value_dot = 1.0;
return start_Node->derive();
}
double SField::derivative(const double& positio... | {
"domain": "codereview.stackexchange",
"id": 45406,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, performance, api, symbolic-math",
"url": null
} |
c++, performance, api, symbolic-math
///////////////////////////////////////////////////////////////////////////////////////////////
//UNOP/////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////... | {
"domain": "codereview.stackexchange",
"id": 45406,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, performance, api, symbolic-math",
"url": null
} |
c++, performance, api, symbolic-math
///////////////////////////////////////////////////////////////////////////////////////////////
//BASEUNOP/////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////... | {
"domain": "codereview.stackexchange",
"id": 45406,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, performance, api, symbolic-math",
"url": null
} |
c++, performance, api, symbolic-math
constexpr double b_subtract (const double& x, const double& y) {return x-y;}
constexpr double b_subtract_del_x (const double& x, const double& y) {return 1.0;}
constexpr double b_subtract_del_y (const double& x, const double& y) {return -1.0;}
constexpr dou... | {
"domain": "codereview.stackexchange",
"id": 45406,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, performance, api, symbolic-math",
"url": null
} |
c++, performance, api, symbolic-math
const IMPLEMENTATION::BaseBinOp add(IMPLEMENTATION::b_add, IMPLEMENTATION::b_add_del_x, IMPLEMENTATION::b_add_del_y);
const IMPLEMENTATION::BaseBinOp multiply(IMPLEMENTATION::b_multiply, IMPLEMENTATION::b_multiply_del_x, IMPLEMENTATION::b_multiply_del_y);
const IMPLEMENTATI... | {
"domain": "codereview.stackexchange",
"id": 45406,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, performance, api, symbolic-math",
"url": null
} |
c++, performance, api, symbolic-math
Code structure, style and readability: Is the code comprehensible? Are there many bad practices?
User Interface I: I tried to make adequate use of data encapsulation, in the sense that the user of the library has only access to those features he should, neither more nor less.
User ... | {
"domain": "codereview.stackexchange",
"id": 45406,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, performance, api, symbolic-math",
"url": null
} |
c++, performance, api, symbolic-math
Since performance requirements always depend on the application, I want to explain what I intend to do with the library:
I already used it to build a solver for arbitrary Hamiltonian systems and in particular computed the dynamics of a three-body system. I want to expand the librar... | {
"domain": "codereview.stackexchange",
"id": 45406,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, performance, api, symbolic-math",
"url": null
} |
c++, performance, api, symbolic-math
That's easy enough to correct:
virtual ~Node() noexcept = default;
Member functions that override really should be marked override to help us get better errors if we mistakenly overload instead (e.g. by forgetting a significant const).
The biggest issue I have with th... | {
"domain": "codereview.stackexchange",
"id": 45406,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, performance, api, symbolic-math",
"url": null
} |
java, websocket
Title: utility for automatic websocket ping-pong and receiving round-trip time reports | {
"domain": "codereview.stackexchange",
"id": 45407,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, websocket",
"url": null
} |
java, websocket
Question: Without ping-pong websocket connections are usually dropped by intermediary proxies/routers after some time of inactivity, so you can't go make yourself a coffee because your chat connection will break by the time you come back ;-] (most browsers such as Chrome or Firefox currently do not do ... | {
"domain": "codereview.stackexchange",
"id": 45407,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, websocket",
"url": null
} |
java, websocket
Additional info: RTT reporting was originally requested by folks who develop some real-time online games. They use it mostly on their server side to calculate and adjust per-participant handicaps on the fly during matches or something like that, so they use intervals of about 200-500ms (to be honest I ... | {
"domain": "codereview.stackexchange",
"id": 45407,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, websocket",
"url": null
} |
java, websocket
Even more clarifications
So first, let me emphasize again, that the main purpose of this utility is to keep websocket connections alive if there's no app-level activity (intermediary proxies and NAT routers tend to drop connections after some time of inactivity). This is especially important for web ap... | {
"domain": "codereview.stackexchange",
"id": 45407,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, websocket",
"url": null
} |
java, websocket
motivation for keep-alive-only mode
After the above situation, for a moment expect-timely-pongs became the only mode of operation, but I received a sad email from a developer who was using this utility as a part of her desktop Java app acting as a websocket client. Some of the users of this app often h... | {
"domain": "codereview.stackexchange",
"id": 45407,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, websocket",
"url": null
} |
java, websocket
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.BiConsumer;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.websocket.*;
import javax.websocket.CloseReason.CloseCodes;
import javax.websoc... | {
"domain": "codereview.stackexchange",
"id": 45407,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, websocket",
"url": null
} |
java, websocket
/** 55s as majority of proxies and NAT routers have a timeout of at least 60s. */
public static final int DEFAULT_INTERVAL_SECONDS = 55;
final int failureLimit; // negative value means keep-alive-only mode
final boolean synchronizeSending;
final ScheduledExecutorService scheduler = E... | {
"domain": "codereview.stackexchange",
"id": 45407,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, websocket",
"url": null
} |
java, websocket
/**
* Configures and starts the service in {@code expect-timely-pongs} mode: each timeout adds to a
* given {@link Session connection}'s failure count, unmatched pongs are ignored.
* @param interval interval between pings and also timeout for pongs. While this class does not
* e... | {
"domain": "codereview.stackexchange",
"id": 45407,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, websocket",
"url": null
} |
java, websocket
// design decision note: using interval as timeout simplifies things A LOT. Using a separate
// SHORTER duration for a timeout is still pretty feasible and may be implemented if there's
// enough need for it. Allowing a timeouts longer than intervals OTHO would required stacking
// of pings... | {
"domain": "codereview.stackexchange",
"id": 45407,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, websocket",
"url": null
} |
java, websocket
// block of constructor variants using some default values:
/**
* Calls {@link #WebsocketPingerService(long, TimeUnit, int, boolean)
* WebsocketPingerService(intervalSeconds, SECONDS, failureLimit, synchronizeSending)}
* ({@code expect-timely-pongs} mode).
*/
public Websocke... | {
"domain": "codereview.stackexchange",
"id": 45407,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, websocket",
"url": null
} |
java, websocket
* WebsocketPingerService(interval, unit, false)} ({@code keep-alive-only} mode).
*/
public WebsocketPingerService(long interval, TimeUnit unit) {
this(interval, unit, false);
}
/**
* Calls {@link #WebsocketPingerService(long, TimeUnit, boolean)
* WebsocketPingerServic... | {
"domain": "codereview.stackexchange",
"id": 45407,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, websocket",
"url": null
} |
java, websocket
/**
* Registers {@code connection} for pinging.
* Usually called in
* {@link javax.websocket.Endpoint#onOpen(Session, javax.websocket.EndpointConfig) onOpen(...)}.
*/
public void addConnection(Session connection) {
addConnection(connection, null);
} | {
"domain": "codereview.stackexchange",
"id": 45407,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, websocket",
"url": null
} |
java, websocket
/**
* Registers {@code connection} for pinging and receiving round-trip time reports via
* {@code rttObserver}.
* Usually called in
* {@link javax.websocket.Endpoint#onOpen(Session, javax.websocket.EndpointConfig) onOpen(...)}.
* <p>
* Upon receiving a pong matching the mo... | {
"domain": "codereview.stackexchange",
"id": 45407,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, websocket",
"url": null
} |
java, websocket
connectionPingPongPlayers.put(
connection,
new PingPongPlayer(connection, failureLimit, synchronizeSending, rttObserver)
);
} | {
"domain": "codereview.stackexchange",
"id": 45407,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, websocket",
"url": null
} |
java, websocket
// design decision note: it seems that in vast majority of cases it is most conveniently for
// developers if a receiver of RTT reports is the Endpoint instance associated with the
// connection which reports concern. Container Threads calling Endpoints are bound by a
// concurrency contrac... | {
"domain": "codereview.stackexchange",
"id": 45407,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, websocket",
"url": null
} |
java, websocket
/**
* Stops the service.
* After a call to this method the service becomes no longer usable and should be discarded.
* @return {@link Session connections} that were registered at the time this method was called.
*/
public Set<Session> stop(long timeout, TimeUnit unit) {
... | {
"domain": "codereview.stackexchange",
"id": 45407,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, websocket",
"url": null
} |
java, websocket
int failureCount = 0;
/** Retained after the most recent ping for comparison with incoming pongs. */
ByteBuffer pingDataBuffer;
/**
* Send timestamp of the most recent ping to which a matching pong has not been received
* yet. {@code null} means that a matching... | {
"domain": "codereview.stackexchange",
"id": 45407,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, websocket",
"url": null
} |
java, websocket
/** Called by the {@link #scheduler}'s worker {@code Thread}. */
synchronized void sendPing(byte[] pingData) {
if (pingTimestampNanos != null) { // the previous ping has timed-out
previousPingTimedOut = true; // report loss on receiving a subsequent pong
... | {
"domain": "codereview.stackexchange",
"id": 45407,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, websocket",
"url": null
} |
java, websocket
/** Called by a container {@code Thread}. */
@Override
public void onMessage(PongMessage pong) {
final var pongTimestampNanos = System.nanoTime();
boolean reportPreviousPingTimedOut;
Long rttToReport = null;
synchronized (this) {
... | {
"domain": "codereview.stackexchange",
"id": 45407,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, websocket",
"url": null
} |
java, websocket
Excellent, thank you for helping future maintenance engineers to understand
the design rationale, and
what classes of device to test against if they make a change
I feel this is a moderately long time,
imposing only small overhead,
and so there should be little motivation to support keepalive-only mo... | {
"domain": "codereview.stackexchange",
"id": 45407,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, websocket",
"url": null
} |
java, websocket
I confess I don't understand what's happening here.
Shouldn't we throw fatal InterruptedException if someone asked us to shutdown?
And maybe also stop()?
I'm just unclear on the contract, on the various responsibilities.
keep-alive
/** For both modes: negative {@code failureLimit} means {@code keep... | {
"domain": "codereview.stackexchange",
"id": 45407,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, websocket",
"url": null
} |
java, websocket
Every 55 seconds the app queues up some TCP payload to deliver.
Now depending on the WiFi outage duration, TCP may have backed off
to very long (more than a minute) retrans attempts, or may have
given up, sent RST, and torn down the connection.
Let's assume TCP has backed off but is still hopeful of re... | {
"domain": "codereview.stackexchange",
"id": 45407,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, websocket",
"url": null
} |
java, websocket
the most-recently-sent random bytes.
Send observer strictly positive latency measurements.
Let observer make the judgement call about what to do with "large" latencies. | {
"domain": "codereview.stackexchange",
"id": 45407,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "java, websocket",
"url": null
} |
c++, performance, object-oriented, design-patterns
Title: Terminal Graphical Visualizer, using a queue of different matrices
Question: I built a project in which I provide a string input or a whole matrix to configure a frame, create a bunch of different frames and push them into a queue and finally print them in ord... | {
"domain": "codereview.stackexchange",
"id": 45408,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, performance, object-oriented, design-patterns",
"url": null
} |
c++, performance, object-oriented, design-patterns
public:
graphical_visualizer();
std::queue<frame> get_frame_queue() const;
void add_frame(frame frame);
void print_sequence(const std::chrono::milliseconds millis);
};
struct input
{
size_t height_start;
size_t height_length;
size_t widt... | {
"domain": "codereview.stackexchange",
"id": 45408,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, performance, object-oriented, design-patterns",
"url": null
} |
c++, performance, object-oriented, design-patterns
char printable_char = input_sections[4][0]; //should always be a string of length 1
for(size_t i = height_start; i <= height_start + height_length - 1; ++i)
{
for(size_t j = range_start; j <= range_start + range_length - 1; ++j)
{
... | {
"domain": "codereview.stackexchange",
"id": 45408,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, performance, object-oriented, design-patterns",
"url": null
} |
c++, performance, object-oriented, design-patterns
std::queue<frame> graphical_visualizer::get_frame_queue() const
{
return frame_queue;
}
void graphical_visualizer::add_frame(frame frame)
{
frame_queue.push(frame);
}
void graphical_visualizer::print_sequence(const std::chrono::milliseconds millis)
{
std... | {
"domain": "codereview.stackexchange",
"id": 45408,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, performance, object-oriented, design-patterns",
"url": null
} |
c++, performance, object-oriented, design-patterns
// ...
std::cout << current_char.color_code << current_char.character;
It's just more readable, and it doesn't add a whole lot of code.
The matrix
There are two things about the way you store your data that makes it quite inefficient. A std::vector<std::... | {
"domain": "codereview.stackexchange",
"id": 45408,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, performance, object-oriented, design-patterns",
"url": null
} |
c++, performance, object-oriented, design-patterns
This way you only store a pointer to the commonly used string, instead of copying it again and again.
Variable names
When you declare void add_frame(frame frame), you make things quite confusing. frame now means something different inside the function as it does outsi... | {
"domain": "codereview.stackexchange",
"id": 45408,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, performance, object-oriented, design-patterns",
"url": null
} |
c++, performance, object-oriented, design-patterns
Things to think about: What is the purpose of alter_frame() if all it does is call parse_input()? You have one function with two names! And do you really want is_valid_input() to be part of the public API? Should this not be a private function?
By the way, is_valid_in... | {
"domain": "codereview.stackexchange",
"id": 45408,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, performance, object-oriented, design-patterns",
"url": null
} |
c++, strings, search
Title: Fast search for the longest repeating substrings in large text (Rev.2)
Question: This is the second iteration of the Fast search for the longest repeating substrings in large text code review. Special thanks goes to G. Sliepen who conducted the first review.
Functional specification
Having... | {
"domain": "codereview.stackexchange",
"id": 45409,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, strings, search",
"url": null
} |
c++, strings, search
The interface was redesigned according to the proposal and a little bit even more. Since function could fine many different substrings which will repeat the specified number of times, it returns the vector of string_views with all entries in the text so that many resulting substrings with their po... | {
"domain": "codereview.stackexchange",
"id": 45409,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, strings, search",
"url": null
} |
c++, strings, search
My concerns on the current code
To fix the defect when function finds substrings which are repeated not exactly requested number of times, but even more frequently I had to add border checks to ensure the number of repeats (see 2 extra calls to findMatchLengthWithOffsetInSuffixArray in calculateA... | {
"domain": "codereview.stackexchange",
"id": 45409,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, strings, search",
"url": null
} |
c++, strings, search
return max_match_length;
}
I still dislike the max_repetitions threshold. It seems that it is better to limit by maximum and minimum length of found substrings, although this is not so straightforward, since by a new criterion line repeated (exactly) 3 times could be longer than line repeated 2 t... | {
"domain": "codereview.stackexchange",
"id": 45409,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, strings, search",
"url": null
} |
c++, strings, search
I would be happy to avoid this std::fill at the beginning of calculateAdjacents function, but I am not sure if this is possible.
size_t findMatchLength(std::string_view str1, std::string_view str2) {
return std::ranges::mismatch(str1, str2).in1 - str1.begin();
}
size_t findMatchLengthWithOffs... | {
"domain": "codereview.stackexchange",
"id": 45409,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, strings, search",
"url": null
} |
c++, strings, search
What behavior does the user need? If the choice doesn't matter for some reason, then just pick one and go with it.
To fix the defect when function finds substrings which are repeated not exactly requested number of times, but even more frequently I had to add border checks to ensure the number of... | {
"domain": "codereview.stackexchange",
"id": 45409,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, strings, search",
"url": null
} |
c++, strings, search
Why is the call to std::min() there? We already know we have at least repetitions entries starting at i. So we can remove that. Then we can let the loop go from 0 to repetitions:
for (size_t match = 0; match < repetitions; ++match) {
occur.pos.emplace_back(index[i + match]);
}
Maybe now it's ... | {
"domain": "codereview.stackexchange",
"id": 45409,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, strings, search",
"url": null
} |
c++, strings, search
Since findMatchLength() is only ever called from findMatchLengthWithOffsetInSuffixArray(), you could inline the former into the latter. But why not just keep them both?
I would be happy to avoid this std::fill' at the beginning of calculateAdjacents` function, but I am not sure if this is possibl... | {
"domain": "codereview.stackexchange",
"id": 45409,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, strings, search",
"url": null
} |
c++, strings, search
And:
size_t findMatchLengthWithOffsetInSuffixArray(std::string_vioew text,
const std::vector<index_t>& index,
const size_t idx,
ptrdiff_t offset)
{
return ... | {
"domain": "codereview.stackexchange",
"id": 45409,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "c++, strings, search",
"url": null
} |
python, algorithm, functional-programming
Title: Map coloring algorithm functional implementation in python
Question: I'm an autodidact working on map coloring algorithms with backtracking, see chapter 2 of this book.
I tested this implementation with success but I'm still unsure whether it is tricking me somewhere, ... | {
"domain": "codereview.stackexchange",
"id": 45410,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python, algorithm, functional-programming",
"url": null
} |
python, algorithm, functional-programming
def __repr__(self):
return f"Node('{self.s}')"
if __name__ == "__main__":
graph_ = {
(n1 := Node("1")): [(n2 := Node("2"))],
n2: [n1, (n3 := Node("3")), (n4 := Node("4")), (n5 := Node("5")), (n6 := Node("6"))],
n3: [n2, n4],
n4: [n2... | {
"domain": "codereview.stackexchange",
"id": 45410,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python, algorithm, functional-programming",
"url": null
} |
python, algorithm, functional-programming
By naming it _paint(), you already pretty much told us that it
is a helper function. (And then you buried it by nesting,
so it's not like it shall be exported from the module namespace anyway.)
Maybe we see the tail wagging the dog here, given that most of the
function's body ... | {
"domain": "codereview.stackexchange",
"id": 45410,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "python, algorithm, functional-programming",
"url": null
} |
beginner, rust, fractals
Title: Mandelbrot Set image generator in Rust
Question: I'm learning Rust, and as-is tradition, I'm starting out with a Mandelbrot Set explorer as my first project (although, it just produces images so far). When run, it just creates and writes an image to the CWD. The coordinates and colorin... | {
"domain": "codereview.stackexchange",
"id": 45411,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "beginner, rust, fractals",
"url": null
} |
beginner, rust, fractals
logic/mandelbrot_iteration.rs
use num::complex::Complex;
pub type ComplexPoint = Complex<f64>;
fn mandelbrot_iteration(initial: ComplexPoint, current: ComplexPoint) -> ComplexPoint {
let current_sq = current * current;
return Complex {
re: current_sq.re + initial.re,
... | {
"domain": "codereview.stackexchange",
"id": 45411,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "beginner, rust, fractals",
"url": null
} |
beginner, rust, fractals
ui.rs
pub mod text;
pub mod image;
ui/image.rs
use image::{ImageBuffer, Rgb};
use num::{clamp, Num};
use crate::logic::mandelbrot_iteration;
fn wrap<N: Num + Copy>(n: N, min_n: N, max_n: N) -> N {
let limit = max_n - min_n;
return (n % limit) + min_n;
}
fn color_f(real: f64, imag: ... | {
"domain": "codereview.stackexchange",
"id": 45411,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "beginner, rust, fractals",
"url": null
} |
beginner, rust, fractals
fn char_for_iterations(n_iterations: u32, max_iterations: u32) -> char {
let density_perc = n_iterations as f32 / (max_iterations + 1) as f32;
let index = ((DENSITY_SORTED_CHARS.len()) as f32 * density_perc) as usize;
return DENSITY_SORTED_CHARS.as_bytes()[index] as char;
}
pub fn... | {
"domain": "codereview.stackexchange",
"id": 45411,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "beginner, rust, fractals",
"url": null
} |
beginner, rust, fractals
DENSITY_SORTED_CHARS is not used as a string so shouldn't be one - an array of char will be a much better fit. Actually using a slice means you can omit the number of elements:
const MY_ARRAY: &[char] = &[' ', '.', '-', ':', ';', '~', '*', '\\', '/', 'i', '(', '{', 'v', 'x', '?', '@'];
A ratio... | {
"domain": "codereview.stackexchange",
"id": 45411,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "beginner, rust, fractals",
"url": null
} |
homework, database, cobol
Title: COBOL Database Program
Question: For a school project I've created a database program in COBOL and now that I'm finished, I have to write a report on the project.
As one aspect of the report, we have to discuss whether the product (the program) achieved all of the "success criteria" w... | {
"domain": "codereview.stackexchange",
"id": 45412,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "homework, database, cobol",
"url": null
} |
homework, database, cobol
WORKING-STORAGE SECTION.
01 PARSING-DATA.
05 DB-FILE-NAME-INDEX PIC 9(3) USAGE IS
COMPUTATIONAL.
05 PARSING-DONE PIC 9(1).
05 NUM-RECORDS-PARSING-START PIC 9(1).
05 N... | {
"domain": "codereview.stackexchange",
"id": 45412,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "homework, database, cobol",
"url": null
} |
homework, database, cobol
05 WRITE-PARSING-LEN PIC 9(4).
05 WRITE-PARSING-LEN-INDEX PIC 9(1).
05 WRITE-PARSING-VALS-CURRENTLY PIC 9(1).
05 WRITE-PARSING-LEN-CURRENTLY PIC 9(1).
05 WRITE-PARSING-CHAR PIC X(1).
05 WRITE-PARSING-CHAR-A... | {
"domain": "codereview.stackexchange",
"id": 45412,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "homework, database, cobol",
"url": null
} |
homework, database, cobol
PROCEDURE DIVISION.
MAIN.
PERFORM INIT-DATA.
PERFORM GET-INPUT.
PERFORM OPEN-FILE.
INITIALIZE COMMAND.
DISPLAY "Please enter command"
ACCEPT COMMAND.
IF COMMAND = "INITIALIZE"
DISPLAY "Please ent... | {
"domain": "codereview.stackexchange",
"id": 45412,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "homework, database, cobol",
"url": null
} |
homework, database, cobol
OPEN-FILE.
SET COL-VALS-INDEX TO 1.
MOVE 1 TO FILE-EMPTY
MOVE 1 TO NUM-RECORDS-PARSING-INDEX
OPEN INPUT DB-FILE.
PERFORM UNTIL FILE-INITIALIZED = '1' OR EOF = '1' OR
CHAR = '$'
READ DB-FILE
... | {
"domain": "codereview.stackexchange",
"id": 45412,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "homework, database, cobol",
"url": null
} |
homework, database, cobol
(NUM-RECORDS-PARSING-INDEX : 1)
ADD 1 TO NUM-RECORDS-PARSING-INDEX
IF NUM-RECORDS-PARSING-STARTED = 0
MOVE 1 TO
NUM-RECORDS-PARSING-STARTED
... | {
"domain": "codereview.stackexchange",
"id": 45412,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "homework, database, cobol",
"url": null
} |
homework, database, cobol
INITIALIZE-FILE.
ACCEPT INPUT-DATA.
MOVE 0 TO INITIALIZATION-STARTED.
OPEN OUTPUT DB-FILE.
MOVE '@' TO CHAR.
WRITE CHAR END-WRITE.
PERFORM VARYING INPUT-COL-VALS-INDEX FROM 1 BY 1 UNTIL
INPUT-COL-VALS... | {
"domain": "codereview.stackexchange",
"id": 45412,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "homework, database, cobol",
"url": null
} |
homework, database, cobol
NEXT SENTENCE
END-EVALUATE
END-PERFORM.
IF INITIALIZATION-FAILED = 0
MOVE '#' TO CHAR
WRITE CHAR END-WRITE
MOVE 0 TO NUM-RECORDS
PERFORM 18 TIMES
... | {
"domain": "codereview.stackexchange",
"id": 45412,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "homework, database, cobol",
"url": null
} |
homework, database, cobol
WRITE-REC.
ACCEPT INPUT-DATA.
IF INITIALIZATION-FAILED = 1
DISPLAY "Error"
END-IF.
MOVE 0 TO WRITE-PARSING-STARTED.
MOVE 0 to WRITE-PARSING-FAILED.
MOVE 0 TO WRITE-PARSING-LEN-INDEX.
MOVE 0 TO WRITE-P... | {
"domain": "codereview.stackexchange",
"id": 45412,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "homework, database, cobol",
"url": null
} |
homework, database, cobol
MOVE 1 TO WRITE-PARSING-FAILED
DISPLAY "3"
NEXT SENTENCE
END-IF
ELSE IF WRITE-PARSING-VALS-CURRENTLY = 1
SUBTRACT 1 FROM WRITE-PARSING-LEN
IF WRITE-PAR... | {
"domain": "codereview.stackexchange",
"id": 45412,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "homework, database, cobol",
"url": null
} |
homework, database, cobol
UNTIL WRITE-PARSING-INDEX IS GREATER THAN 18
READ DB-FILE END-READ
MOVE NUM-RECORDS (WRITE-PARSING-INDEX : 1) TO
CHAR
REWRITE CHAR
END-PERFORM
CLOSE DB-FILE
... | {
"domain": "codereview.stackexchange",
"id": 45412,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "homework, database, cobol",
"url": null
} |
homework, database, cobol
READ-REC.
MOVE ALL '_' TO DIVIDER (1 : 80).
MOVE 0 TO SEARCH-FAILED.
MOVE 0 TO SEARCH-DONE.
MOVE 1 TO READING-LEN.
MOVE 1 TO READING-LEN-INDEX.
MOVE 0 TO READDEL-VAL.
MOVE 1 TO REGISTER-INDEX.
MOVE 0 TO PA... | {
"domain": "codereview.stackexchange",
"id": 45412,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "homework, database, cobol",
"url": null
} |
homework, database, cobol
DISPLAY LENGTH-REGISTER
END-IF
END-IF
ELSE
DISPLAY "7"
MOVE 1 TO SEARCH-FAILED
END-IF
ELSE IF READDEL-VAL = 1
... | {
"domain": "codereview.stackexchange",
"id": 45412,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "homework, database, cobol",
"url": null
} |
homework, database, cobol
END-IF
END-IF
END-PERFORM.
CLOSE DB-FILE.
DELETE-REC.
MOVE 0 TO SEARCH-FAILED.
MOVE 0 TO SEARCH-DONE.
MOVE 1 TO READING-LEN.
MOVE 1 TO READING-LEN-INDEX.
MOVE 0 TO READDEL-VAL.
... | {
"domain": "codereview.stackexchange",
"id": 45412,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "homework, database, cobol",
"url": null
} |
homework, database, cobol
IF LENGTH-REGISTER = 0
MOVE 1 TO READING-LEN
MOVE 0 TO READDEL-VAL
SUBTRACT 1 FROM COLS-INDEX
IF COLS-INDEX = 0
MOVE COL-VALS-INDEX TO... | {
"domain": "codereview.stackexchange",
"id": 45412,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "homework, database, cobol",
"url": null
} |
homework, database, cobol
Answer: ZOMG, that is frightening along so many dimensions.
Disclaimer: Within the last decade I wrote lots of python code to parse production COBOL database record formats. And as an undergraduate I had roommates who studied COBOL in a non-ironic way.
format
Ok, style points for leaving room... | {
"domain": "codereview.stackexchange",
"id": 45412,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "homework, database, cobol",
"url": null
} |
homework, database, cobol
WTF, where did 501 come from?
We don't like naming our magic constants?
My difficulty is, I simply don't know what it means,
and grep'ing for 501 fails.
OIC, the related DB-FILE-NAME can hold 500 characters.
What, there's no LENGTH-OF-STORAGE-ELEMENT(DB-FILE-NAME)
defined in this dialect of t... | {
"domain": "codereview.stackexchange",
"id": 45412,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "homework, database, cobol",
"url": null
} |
homework, database, cobol
Sorry, I'm getting distracted by the gratuitous datatype changes.
We declared both of those as PIC 9(1).
Yet sometimes we talk about them as character variables,
and sometimes as numeric variables.
Yes, I understand the language lets you get away with it.
But if you're trying to communicate a... | {
"domain": "codereview.stackexchange",
"id": 45412,
"lm_label": null,
"lm_name": null,
"lm_q1_score": null,
"lm_q1q2_score": null,
"lm_q2_score": null,
"openwebmath_perplexity": null,
"openwebmath_score": null,
"tags": "homework, database, cobol",
"url": null
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.