coding style – Defining default values for Boolean arguments in JavaScript

Javascript is somewhat different in this regard as it’s very loose about it type and method definitions, and it fills in a lot of the gaps for you.

In this particular case, the two are completely equivalent. But this relies on two key notions:

  • Javascript doesn’t care about missing method parameters to begin with.
  • You are setting the default value of the method parameter to the default value of a boolean (i.e. false)

If you change either of these notions, it ceases to be equivalent. Below are two examples of this.

However, before we get to the examples, I want to address your question:

Is it usually recommended to define default values for Boolean arguments?

Recommendations are not always done for technical benefit. It could be of a documentative nature.

For example, while the behavior between your two methods is exactly the same, if I were to start using your code, I would infer that someFunction(a, b, x) isn’t intended to be called with missing parameters, whereas if I see someFunction(a, b, x = false), I can infer that whoever designed this method specifically expected that the third parameter might be omitted.

That doesn’t change how the code works, but it does change my understanding of the author’s intention when designing this method, so it changes how I develop this code further (e.g. not going round and “fixing” all method calls which seem to have “forgotten” the third parameter).

So is it recommended? Well, that depends.

  • As a blanket rule? No, that’s silly.
  • As a way to indicate that omitting this parameter in this method is expected and not a problem? Yes, that’s a great way of communicating that to future readers of your code.
  • As a way to actually change how the code behaves? Well, yes, but in your particular example, it doesn’t quite matter since any uninitialized boolean will already be false anyway.

Example 1

For example, if you want x to be true by default. Compare these examples:

someFunctionWithoutOptionalValue(a, b, x)      { console.log(x == true); }  
someFunctionWithOptionalFalse(a, b, x = false) { console.log(x == true); }
someFunctionWithOptionalTrue(a, b, x = true)   { console.log(x == true); }

And we run this script:

someFunctionWithoutOptionalValue(a,b);
someFunctionWithOptionalFalse(a,b);
someFunctionWithOptionalTrue(a,b);

You will notice the following output:

false
false
true

When you define your optional value to be different from what the default value already is, then this makes a change to how the code behaves.


Example 2

While this may be less relevant for you now, if we move to another language which is much stricter with its typing but also has optional parameter values (I pick C# here), then the two examples you gave also are no longer equivalent.

public void SomeFunction(int a, int b, bool x) {}
public void SomeFunctionWithOptional(int a, int b, bool x = false) { }

I’m allowed to do either of these:

SomeFunctionWithOptional(1, 2, true);  // x will be true
SomeFunctionWithOptional(1, 2);        // x will be false

And I’m allowed to call:

SomeFunction(1,2,true);                // x will be true

But I am not allowed to omit a non-optional parameter:

SomeFunction(1,2);                     // COMPILER ERROR

In strongly typed languages, you must mention that a method parameter is optional before you are allowed to actually leave it empty when calling the method.

sparse arrays – How to write correctly some arguments in SparseArray

I am struggling to put an argument in SparseArray. Let’s consider the following example

dim = 9;
s = SparseArray({{i_, i_} :> 1.0 + I, Band({2, 1}) -> 2.0, 
   Band({1, 2}) -> 2.0}, {dim, dim}, 0.0)

This works correctly and generates a matrix 9×9 with two diagonals having the value 2.0. Now I want to change some values on one of those diagonals, or better said, when I define s I would like to have a different value of 2.0 but only on some certain positions of that diagonal. For that I use an array lt specifying those positions in s,
lt={3,6};, because one can specify manually a value for a certain position (for example {1,1}->4.0) and I tried to put the following Row(Flatten(Table({i,i+1}->0.0,{i,lt}),1),","), having

s = SparseArray({{i_, i_} :> 1.0 + I,Row(Flatten(Table({i, i + 1} -> 0.0, {i, lt}), 1), ","), Band({2, 1}) -> 2.0, 
   Band({1, 2}) -> 2.0}, {dim, 
   dim}, 0.0)

but it failed, but If I put manually the positions

s = SparseArray({{i_, i_} :> 1.0 + I,{3,4}->0.0,{6,7}->0.0, Band({2, 1}) -> 2.0, 
   Band({1, 2}) -> 2.0}, {dim, 
   dim}, 0.0)

it works. Of course this example is small and I can write it manually, but in real nb dimensions are bigger, that is why I use a Table command. Maybe the question could be also seen as how to obtain the output of Table without {}. Any advice is welcome.

Virtual or physical servers: what should I choose? 8 arguments in favor of clouds | Proxies123.com

tch22-1.jpg

Virtual or physical servers: what should I choose? 8 arguments in favor of clouds​

The days when a significant part of office space was occupied by physical servers go to the past. Fewer companies want to clutter their offices with hardware. However, this has not completely become a part of history yet. Since the myths about clouds are hovering around, some users are still in the arms of physical servers. If you are also in doubt about whether to choose a virtual server in the cloud or a physical server in the office, we recommend you familiarize yourself with the specifics of each approach. https://tucha.cloud/en/blog/busines…what-should-i-choose-8-arguments-favor-clouds

And we will be glad to solve your most interesting cloud problems! Write to the address sales@tucha.ua or call +380 44 583-5-583. Tucha is always in touch.

unity – Passing properties as arguments such that the resulting class can modify the original

I’m really not experienced with c# so maybe my whole methodology is wrong but here goes.

I’m trying to build a GUI that allows many many parameters to be modified in real time and have a central repository for all those variables. So I am trying to build a wrapper class around the slider so I don’t have to explicitly link it to each property in the parameters class manually, and make it easier to add other generic functionalities like events or whatever.

So right now I have a UI class that holds the sliders, a slider wrapper class that holds some extra functionality, and a central parameters class. The central class shouldn’t have any dependencies of the other two classes.

The UI class instantiates the slider wrapper class, and passes a Unity slider object. That part works fine.
It also passes the property from the central parameter class to which it should be linked. That’s the part I’m stuck on.

UI class:

public class UIParams : MonoBehaviour
{
 
    private GeneralParams _centralParams;   // reference to central parameters class
    private Transform _mainUI;               // reference to main UI panel
    private Transform _panel1;               // reference to sub panel
 
    private MySlider _mySlider1;           // instance of my slider wrapper class
    // more sliders go here
   
    void Start()
   
    {
        //init
        _centralParams = GameObject.FindObjectOfType<GeneralParams>();
        var Panel1 = GameObject.Find("MainUI").transform.Find("Panel1");
 
       
       
        //sliders
        _mySlider1 = new MySlider(
            Panel1.Find("Slider1").GetComponent<Slider>(),  //pass the actual slider to the wrapper
            _centralParams.Parameter_1);                     //pass the central parameters property to the wrapper
       
       
        // more sliders go here
   
    }
 
}

Slider wrapper class:

Code (CSharp):
class MySlider
{
    private Slider _slider;                 // object to hold the slider
    private float _sliderValue;                   // value of the slider
 
    public MySlider(Slider Slider, float CentralParameterProperty)
    {
        _slider = Slider;                                                   // reference to Slider
        _slider.onValueChanged.AddListener(delegate { update();});      // listen for changes to slider, don't want to be checking all the time
        _sliderValue = CentralParameterProperty;                            // set slider to default value in CentralParams. How do I modify that value???
    }
 
    private void update()
    {
        _sliderValue = _slider.value;       // how do I change the original value from Central Params without explicitly linking each property manually?
    }
}

Central parameter class:

Code (CSharp):
public class CentralParams : MonoBehaviour
{
   
    public Action GeneralUpdateEvent;       // tell other classes when an update has occured
   
    (SerializeField)
    private float parameter_1;
    public float Parameter_1
    {
        get => parameter_1;
        set
        {
            parameter_1 = value;
            GeneralUpdate();
        }
    }
   
    // more parameters go here
   
 
    void GeneralUpdate()
    {
        GeneralUpdateEvent?.Invoke();
    }
}

Passing the float CentralParameterProperty into the MySlider instance works to set the default value of the slider. But obviously from that point onwards the slider only modifies the internal variable _sliderValue, not the property of the central class.

Can I set it up so I pass some object from the UI class into the MySlider on instantiation such that the MySlider instance can both get and set the values of the CentralParams property, without explicitly linking to central class within the MySlider class? Or is this just Wong?

Hope that made sense…

sharepoint online – Exception calling “ExecuteQuery” with “0” argument(s): “The underlying connection was closed: An unexpected error occurred on a send-SPO

sharepoint online – Exception calling “ExecuteQuery” with “0” argument(s): “The underlying connection was closed: An unexpected error occurred on a send-SPO – SharePoint Stack Exchange

Passing arguments to YourPhone app to send message from PC to my cell from security app than can run on alerts

I’m wondering if it’s possible to pass arguments to YourPhone app to send message from my PC to my cell from my security app than can then run YourPhone on alerts.

For instance, on an alert from my security software ISpy it can run a batch file calling YourPhone app so if I can pass it my cell number I would get an alert on my cell. I know how to start the YourPhone app from the command line but I don’t know if it accepts arguments 🙁

I have searched everywhere and can’t find diddley!

Thanks,

Tom

Django | Execute() takes from 2 to 3 positional arguments but 7 were given

Al ejecutar la insert sql, me devuelve el siguiente error. Al hacer una sola insert hace perfecto, pero al concatenar varios valores me devuelve el siguiente error:
¿Es posible que esté mal la manera de concatenar %s, %s, %s?
Gracias.

Error:

introducir la descripción de la imagen aquí

View:

...
        cursor = connection.cursor()
        query = ''' 
                INSERT INTO testapp_useranswers (user,modality,numberQuestion,correctAnswerCounterSameQuestion,wrongAnswerCounterSameQuestion) 
                VALUES (%s,%s,%s,%s,%s) 
         '''
        cursor.execute(query, (userAnswer),(modalityPost),(numberQuestionPost),(ansOK),(ansWrong))
        print("Insert completo")
...

Model:

class UserAnswers(models.Model):
    user = models.ForeignKey(User,on_delete=models.CASCADE,null=True,blank=True)
    modality = models.ForeignKey(Modality,on_delete=models.CASCADE,null=True,blank=True)
    numberQuestion = models.IntegerField('Número pregunta',null=True,blank=True)
    correctAnswerCounterSameQuestion=models.IntegerField('Veces que se ha respondido una pregunta correctamente',null=True,blank=True)
    wrongAnswerCounterSameQuestion=models.IntegerField('Veces que se ha respondido una pregunta incorrectamente',null=True,blank=True)

differential equations – Compile::argcompten: The comparison, Less, is invalid for tensor arguments

I am trying to define a simple “Compile function” in MMA 12.2, which takes the form

comcheck = 
  Compile({{mp0, _Real, 
     4}, {deps0, _Real}, {stressN0, _Real}, {alphaN0, _Real}, {epN0, 
_Real}}, Module({mp = mp0, deps = deps0, stressN = stressN0, 
     alphaN = alphaN0, epN = epN0, Emod, beta, Hmod, Y0, stress, 
     alpha, ep, ftol, stresstr, etatr, fyld, dep, mm1, mm2}, 
    Emod = mp((3));(*dep=0.0;*)beta = mp((2)); Hmod = mp((1)); 
    Y0 = mp((2)); ftol = Y0*10;
    mm2 = 0;
    stresstr = stressN + Emod*deps; etatr = stresstr - alphaN; 
    fyld = Abs(etatr) - (Y0 + beta*Hmod);
    If(fyld - ftol < 0, mm2 = 3, mm2 = 4);
    {mm2}), Parallelization -> True, CompilationTarget -> "C");

These code cannot be used due to this error:

Compile::argcompten: The comparison, Less, is invalid for tensor
arguments.

What does “The comparison, Less, is invalid for tensor arguments” mean? and how to remove this error?

Thanks in advance!

linux – Executing single shell script parallelly at same time with different arguments

Consider a script lets say test.sh which accepts file no as argument which process huge files based on argument. So whenever I am executing it as “nohup ./test.sh 01 &” it does the job, I have requirement where same needs to be executed parallelly for 8 files and I am able to achieve that with different arguments.

Following are my major queries on same:

  1. Whenever I am executing same script parallelly with different arguments are their any chances that one instance may alter another instance variables as I am using only one copy of script ?
  2. If no then how is this avoided or done, what avoids this conflict ?

Any reference to read on the same of brief explanation would be really helpful, thanks!!

Note: I have tried this approach & have observed no conflicts till date just want to know the reason behind the same as I am not able to find any reference for the same.

list manipulation – For loop over several arguments with different length each

I have a set of text files named in indexed way d1, d2, d3, d4, d5, d6, d7, d8, d9.

I want to read them by Mathematica and export them back with other index names N(s1f1+s1f1), N(s1f1+s2f2), N(s1f1+s3f3),N(s2f2+s1f1), N(s2f2+s2f2), N(s2f2+s3f3),N(s3f3+s1f1), N(s3f3+s2f2), N(s3f3+s3f3)

I did a for loop as follows

 For(i = 1, i <= 3, i++, 
  For(j = 1, j <= 3, j++, 
   For(k = 1, k <= 3, k++, 
    Export(StringJoin("N", "(", "s", TextString(i), "f", 
      TextString(i), "+", "s", TextString(j), "f", TextString(j), ")",
       ".txt"), Import(StringJoin("d", TextString(k), ".txt"))))));

But the problem is the resulting files contain data from d9 only

DreamProxies - Cheapest USA Elite Private Proxies 100 Private Proxies 200 Private Proxies 400 Private Proxies 1000 Private Proxies 2000 Private Proxies ExtraProxies.com - Buy Cheap Private Proxies Buy 50 Private Proxies Buy 100 Private Proxies Buy 200 Private Proxies Buy 500 Private Proxies Buy 1000 Private Proxies Buy 2000 Private Proxies ProxiesLive Proxies-free.com New Proxy Lists Every Day Proxies123