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.

How to set default phone for Google 2FA prompt (same phone number) without using Gmail prompt?

I don’t know where else to ask this, so I’ll start here…
I want to use a Google prompt for 2FA on my new iphone. I’ve set it up and it shows up on the list of phones on my Google account, however when I try to sign in, the notification is sent to my old (Galaxy A30) phone:

notification

To actually get a notification on my iphone, I need to “Try another way”:

try another way

This forces me to either use Google authenticator or Gmail. I prefer to receive a prompt on my phone without having to open another app.

How can I achieve this?

Thanks

How to customize the default download location for Paclets


Your privacy


By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.




magento2 – How to get Customer default shipping address in Magento 2

Try the below code and let me know if you need more details.

$customerRepository = MagentoCustomerApiCustomerRepositoryInterface
$addressRepository = MagentoCustomerApiAddressRepositoryInterface
//define above variables in constructor.
 $customer = $this->customerRepository->getById($customerId);
 $shippingAddressId = $customer->getDefaultShipping();

//get default billing address
 try {
    $shippingAddress = $this->addressRepository->getById($shippingAddressId);
} catch (Exception $e) {
    //
}

sql server – Why does FROM multiple tables default to cartesian product?

I’m not familiar with how concatenate works in Pandas, but I think CROSS JOIN is the only clause that makes sense with nothing else specified in this case.

You certainly couldn’t vertically concatenate (UNION in SQL) the tables because they could vary in columns (by number of columns and their data types) and how would one horizontally concatenate them, i.e. on what conditions could you align the rows from each table to relate them together as a single row when nothing is specified? I think the simplest answer in the context of relational logic is CROSS JOIN.

Furthermore concatenate in Pandas seems to be meant to operate on a different type of objects than a relational database. While yes technically those objects can be considered a set of values, the criteria that describes them and the constraints those values live by are not the same as a relational table of records with columns that observe different data types, and are potentially bound by database constraints, etc.

To achieve a similar looking outcome of what the single concatenate operation does in SQL, you would need to apply a series of operations potentially including PIVOT, UNION, and CAST, for example.

Documentation on iTunes default .mp4 framerate, khz, channels, etc… For iTunes audio files

Looking for documentation on the correct format and output for every .mp4 file streamed and uploaded to the iTunes music store. So that when modifying a .mp3 or .mp4 file that is compatible with iTunes standards.

Is this documentation listed somewhere.

8 – What is the correct order of disabling the default contact form on Drupal?

Drupal comes with a default contact form on each site we install. And while we already have the webforms and recaptcha module installed, some of our site owners still use the default contact form found in
/admin/structure/contact.

I need to remove them because when they are enabled, the site is prone to spam attacks. I’ve had a few instances where some of the sites had form submissions with PDF file uploads of inappropriate content. So you see how this is a security risk for our organization.

I removed that contact form in my local site by disabling the following modules in this order:
contact form
contact storage
contact

But I need to do this for all our sites now, so I wrote the following in my profiles_update() function:

function my_profile_update_8011() {
    $config = Drupal::configFactory();
    $moduleHandler = Drupal::service('module_handler');

    if($moduleHandler->moduleExists('lightning_contact_form')) {
        Drupal::service('module_installer')->uninstall(('lightning_contact_form'));
    }
    if($moduleHandler->moduleExists('contact_storage')) {
        Drupal::service('module_installer')->uninstall(('contact_storage'));
    }
    if($moduleHandler->moduleExists('contact')) {
        Drupal::service('module_installer')->uninstall(('contact'));
    }

}```

When I deploy this update to our dev environment, it would work on most of the sites, but fail on the rest. They all have this same error message:

The error output from the server was: > (notice) Update started: my_profile_update_8011

(error) SQLSTATE(42S22): Column not found: 1054 Unknown column ‘id’ in ‘where clause’: SELECT 1 AS expression
FROM
{contact_message} t
WHERE id IS NOT NULL
LIMIT 1 OFFSET 0; Array
(
)

(error) Update failed: my_profile_update_8011
(error) Update aborted by: my_profile_update_8011
(error) Finished performing updates.


All our sites share the same codebase, so I don't know where my update hook went wrong.
Is there a better way of disabling these modules?

thanks,
Kevin

block editor – Gutenberg Default attributes are empty

I’m not sure if I’m missing something here but when I console.log my attributes I am getting an empty object. Shouldn’t it show the default data of all my attributes. What I am doing wrong here.

import { __ } from '@wordpress/i18n';
import { registerBlockType } from '@wordpress/blocks';
import { useEffect } from '@wordpress/blocks';
import { PluginDocumentSettingPanel } from '@wordpress/edit-post';
import GoogleMap from './GoogleMap.js';
import { Component } from '@wordpress/element';
import axios from 'axios';

registerBlockType( 'splash-blocks/google-maps', { 
    title: __('Google maps locations', 'google-maps'),
    icon: 'megaphone',
    category: 'common',
    keyword: (
        __( 'Display Google maps locations' ),
    ),
    atrributes: {
        markers: {
            type: 'array',
            default: ({
                lat: 37.79406,
                lng: -122.4002,
            }),
        },
        icon: {

        },
    address: {
        type: 'string',
        default: 'xxxxxxxxx',
        }, 
        api_key: {
        type: 'string',
        default: 'xxxxxxxxx',
        }
    },
    edit({ attributes, setAttributes }) {

        console.log(attributes)
        //Console shows empty object
        return ( 
            <div id='google-map'>
            </div>
        )
    },
    save: null,
})

default applications – Which “app” is responsible for “open with”

Which (app / piece of software) that is responsible for this function?

The dialogue box that asks for which app to use.
    – complete action using:
    – choose an app:
    – open with:

Is it a package?
Can I disable it?

I know there is “open by default” and “app preferences”
Where you can set the default app to open automatically for some files, links, etc.

But sometimes the dialogue doesn’t show up for certain actions. Like trying to upload a file on a specific browser doesn’t prompt the dialogue but instead goes automatically to camera. Which is super weird.

Would appreciate any thread of info.


Edit:
Screenshot
“uploading file to Microsoft form using Google Chrome”

"complete action with" screenshot

datetime – I want to use dd/mm/yy as date format in a custom form instead of default mm/dd/yy

I am using the following date form element.

$form('dobnew') = (
  '#type' => 'date',
  '#title' => t('Birth Date new'),
  '#date_date_format' => 'd/m/Y',
  '#default_value' => date('d/m/Y'),
  '#required' => TRUE,
);

The date widget I get is the following one.

screenshot