IS good idea to use constants instead of raw literal strings and when is a bad one? [duplicate]

This question already has an answer here:

  • Usage of magic strings/numbers [closed] 4 answers

Usually when I code in PHP I try to avoid using literal strings in cases such as:

define('IMAGE_DOWNLOAD_PATH','./data/images/'); define('IMAGE_FILENAME_PREFIX','myapp_'); $  url="http://exaple.com/image.png"  function genFilenamesForDownload(string $  url): string {     $  extention = pathinfo($  url, PATHINFO_EXTENSION);      return IMAGE_DOWNLOAD_PATH.IMAGE_FILENAME_PREFIX.hash('sha512',$  url).".$  {extention}"; }  

My rationale behind this is that using constants I make my code more self-documenting and I do not spend time to guess what each literal value is.

But on my experience some developers that I collaborate with find this approach more confusing whilst I find this approach more easy-to-understand especially for new employees or collaborators to the project.

So I wondered which approach is better, to directly use literals or to define my literals as constants? Also is this approach good for all cases?

Empty string or empty string literal?

Is there some reason, from the programmer’s point of view, to say “empty string” instead of “empty string literal”? (Yes, 1 additional word, but it is more explicit and logic. Isn’t it?)

a = "foo" b = "" 
  • a and b are string variables.
  • "foo" is string literal (nonempty).
  • "" is empty string, i.e. empty string literal.

Is it the correct understanding?

error unclosed string literal

                st = con.prepareStatement("SELECT venta.`Codigo_V` AS venta_Codigo_V, venta.`Total` AS venta_Total, venta.`Fecha` AS venta_Fecha, detalle_venta.`Codigo_V` AS detalle_venta_Codigo_V, detalle_venta.`Codigo_P` AS detalle_venta_Codigo_P, detalle_venta.`Precio` AS detalle_venta_Precio, detalle_venta.`Cantidad` AS detalle_venta_Cantidad, detalle_venta.`Descuento` AS detalle_venta_Descuento, detalle_venta.`SubTotal` AS detalle_venta_SubTotal, producto.`Codigo_P` AS producto_Codigo_P, producto.`Descripcion_P` AS producto_Descripcion_P, producto.`Precio_P` AS producto_Precio_P FROM `venta` venta INNER JOIN `detalle_venta` detalle_venta ON venta.`Codigo_V` = detalle_venta.`Codigo_V` INNER JOIN `producto` producto ON detalle_venta.`Codigo_P` = producto.`Codigo_P` 

“); tengo este error y no se como arreglarlo

How can one read the time in GPG’s Literal Data Packet?

RFC 4880 says that the Literal Data Packet’s time stamp is four octets long. Listing packets shows that it is five octets long, at least in GnuPG 2.2.6.

The time stamp comes after the word “created”, and is comprised of digits 0 to 9. How can it be read?

Example:

:literal data packet: mode b (62), created 1562530941, name=”My File”

iOS 12 (iPad) Scoped literal IPv6 addresses

I have a raspberry pi running dnsmasq on my lan with both IPv4 and IPv6. I would like to use the custom dns setting on the iPad to use the raspberry rather than the DNS offered by the router in DHCP and router announcement, (I don’t want everything on my lan to use the pi). I can’t use the global IPv6 address of the Pi because I do not have a static IPv6 subnet.

On my computer I am able to use the fe80 link-local address, but it does not work on the iPad. I am thinking I need to specify a zone index, but I don’t know what it would be. I tried appending %en0 but that did not work.

Is it possible to specify the zone index on iOS, and if so, what format is used?

(Using terminology from Wikipedia IPv6 article)

Is a literal out of range a syntax error or a semantic error?

I am reading more about the differences between syntax and semantics, but I am still wondering about this one.

Let’s assume that we have a language that only allows integers to be in the range of 0-255, so 8-bits, and the parser receives 256 or 257.

Should that be an error of syntax or semantics?


Resources I’ve checked:

  • https://stackoverflow.com/questions/39522765/distinguishing-between-lexical-error-and-semantic-error
  • What's the difference between syntax and semantics?
  • https://www.guru99.com/compiler-design-phases-of-compiler.html

Stacking multiple query formulas throws “an Array Literal was missing values for one or more rows”

I am attempting to run multiple queries where it adds rows where if F is blank, then it skips those rows, then runs the query again and replaces row F with row G.

I have a much more complicated formula doing the same thing but more variations, columns D(blank or not) – E and F(blank or not) – G

The following formula works

=SORT(ArrayFormula({  IFERROR(QUERY('6 Star Gear Sets (Hidden)'!A6:AA,   "select A, B, C, D, F, H, N, I, J, K, L, M     where A != ' ' AND D IS NOT NULL AND F IS NOT NULL order by F desc"));   IFERROR(QUERY('6 Star Gear Sets (Hidden)'!A6:AA,    "select A, B, C, E, F, H, N, I, J, K, L, M     where A != ' ' AND D IS NULL AND F IS NOT NULL order by F desc"));   IFERROR(QUERY('6 Star Gear Sets (Hidden)'!A6:AA,    "select A, B, C, D, G, H, N, I, J, K, L, M     where A != ' ' AND D IS NOT NULL AND F IS NULL order by F desc"));   IFERROR(QUERY('6 Star Gear Sets (Hidden)'!A6:AA,    "select A, B, C, E, G, H, N, I, J, K, L, M     where A != ' ' AND D IS NULL AND F IS NULL order by F desc"))  }),5,FALSE) 

But my more simple version of the same formula returns an error

=SORT(ArrayFormula({  IFERROR(QUERY('5 Star Clubs (Hidden)'!A6:Z,    "select A, B, C, D, E, F, H, I     where A != ' ' AND F IS NOT NULL"));   IFERROR(QUERY('5 Star Gear Clubs (Hidden)'!A6:Z,    "select A, B, C, D, E, G, H, I     where A != ' ' AND F IS NULL"))  }),7,FALSE) 

The error is: In ARRAY_LITERAL, an Array Literal was missing values for one or more rows.

A link to a copy of the google sheets is as follows:

https://docs.google.com/spreadsheets/d/1s6spmfCVP6P331Zr9xfE9kiei3Wly6FRQCdA8Y3e7tA/edit?usp=drivesdk.


Additional Question

UPDATED FORMULA of the original working formula

=SORT( ArrayFormula( { IFERROR( QUERY( '6 Star Gear Sets (Hidden)'!A6:AA, "select A, B, C, D, F, H, N, I, J, K, L, M where A != ' ' AND D IS NOT NULL AND F IS NOT NULL order by F desc"),{"","","","","","","",""}); IFERROR( QUERY( '6 Star Gear Sets (Hidden)'!A6:AA, "select A, B, C, E, F, H, N, I, J, K, L, M where A != ' ' AND D IS NULL AND F IS NOT NULL order by F desc"),{"","","","","","","",""}); IFERROR( QUERY( '6 Star Gear Sets (Hidden)'!A6:AA, "select A, B, C, D, G, H, N, I, J, K, L, M where A != ' ' AND D IS NOT NULL AND F IS NULL order by F desc"),{"","","","","","","",""}); IFERROR( QUERY( '6 Star Gear Sets (Hidden)'!A6:AA, "select A, B, C, E, G, H, N, I, J, K, L, M where A != ' ' AND D IS NULL AND F IS NULL order by F desc"),{"","","","","","","",""}) } ) ,5,FALSE,4,FALSE)

WORK AROUND

In the 6 Star Gear Sets (Hidden) sheet the formula references, there is a row with A column “zzzzz” and both F and G is blank. When this row is called using the above ArrayFormula, I use a Conditional Format to hide all rows with “zzzzz”.

QUESTION

If I remove the row with “zzzzz” in column A from the hidden sheet, I recieve an error.. why?

ADDITIONAL INFO

Breaking the formula into individual QUERY forumlas and removing IFERROR, shows the 3rd query is empty and returns #N/A error, but the 4th query also does not return any results and it does not give such an error. I figured the IFERROR statement would handle this but to no avail.

UPDATE

Found the 4th query isn’t returning empty. It is actually returning blank cells. Which again, adds to the list of questions. Because I have the IFERROR function removed and where A != ' ' I thought would handle this. Is that not Where A DOES NOT MATCH blank?

I’ve tried wrapping it in an IF(IFNA()) formula but I guess you can’t use IFNA outside Conditional Formatting because it says IFNA() isn’t a known function.

UPDATE 2

For some reason I immediately forgot the part about the number of blank arguments in the IFERROR statement needs to match the number of columns being referenced.

However, =SORT is no longer working correctly as there is now a blank row at the top of the new table and I still do not have a good explanation of why the 4th Query is filling the table with blank rows.

UPDATE 3

In the A column of my “6 Star Gear Sets” sheet, I have a formula that numbers everything in the order they appear unless the B column is blank. For some reason, the blank row that is inserted due to the =IFERROR(,) isn’t actually being treated as being blank.

In additional, my =SORT orders everything in descending order by the F and then E column. However, it treats the F and E in the inserted blank row as the highest value row.

UPDATED FORMULA

=SORT( ArrayFormula( { IFERROR( QUERY( '6 Star Gear Sets (Hidden)'!A6:AA, "select A, B, C, D, F, H, N, I, J, K, L, M where A != ' ' AND D IS NOT NULL AND F IS NOT NULL order by F desc"),{"","","","","","","","","","","",""}); IFERROR( QUERY( '6 Star Gear Sets (Hidden)'!A6:AA, "select A, B, C, E, F, H, N, I, J, K, L, M where A != ' ' AND D IS NULL AND F IS NOT NULL order by F desc"),{"","","","","","","","","","","",""}); IFERROR( QUERY( '6 Star Gear Sets (Hidden)'!A6:AA, "select A, B, C, D, G, H, N, I, J, K, L, M where A != ' ' AND D IS NOT NULL AND F IS NULL order by F desc"),{"","","","","","","","","","","",""}); IFERROR( QUERY( '6 Star Gear Sets (Hidden)'!A6:AA, "select A, B, C, E, G, H, N, I, J, K, L, M where A != ' ' AND D IS NULL AND F IS NULL order by F desc"),{"","","","","","","","","","","",""}) } ) ,5,FALSE,4,FALSE)

UPDATED LINK

Below is an updated copy of my spreadsheet.

https://docs.google.com/spreadsheets/d/17Ev1_Scobnl16H9TuTrHK_es7fZGkMqHyvmpWWWVbow/edit?usp=drivesdk

Creating a Literal Dictionary: Research and Reference Help

So I want to create a dictionary that I can add to a Word Doc.

What I have in my mind (based on a lot of assumptions): a list of words tagged with parts of speech such as Proper Noun (name), Noun, and Verb, so that the grammar checker won’t throw a fit.

I tried to do a little research to see if my assumptions are valid. My first target was how to add dictionaries and how the native Microsoft dictionary is constructed. (I hoped looking into the native dictionary would show me what the possibilities were, let me refine my vision and especially use it as a leaping off point.)

Instead of learning anything, I came up against an absolute wall of CUSTOM.dic. There’s tons of posts and information about using the default custom dictionary, how to add and delete and edit it. There’s practically nothing about the native dictionary or its format or how to develop a dictionary. Every search term I try comes back to CUSTOM.dic.

Searching on my computer, I managed to find the Microsoft directories and the dictionary files. I discovered they have the extension (.LEX), but I’m not sure how to read them or what exactly this file extension is.

I did eventually came across a reference to “Hunspell” and “MySpell” and “ASpell”, but nothing indicating whether such a dictionary could be added to Microsoft Word or how to do so. Is it worth the investment to learn?

EDIT: Considering there are 3rd-party commercial dictionaries available for things like medical terms or physics terms, I know it’s possible, and I already know how to add dictionaries. I don’t know what format those dictionaries come in since I don’t want to spend the money on them just to find their extension, but I know they exist.

I guess my number one question is, can Word Add dictionaries other than *.dic? If they can, what formats? And my stretch goal: how do I write into those other formats?

invalid literal for int() with base 10 ElasticSearch

I have a problem with elasticsearch.

I cannot write string values from pandas df to elasticsearch. I’ getting an error:

ValueError: invalid literal for int() with base 10: 'Marc34' 

Elasticsearch index:

request_body = {         "settings" : {             "number_of_shards": 6,             "number_of_replicas": 1         },          'mappings': {             'doc': {                 'properties': {                     'name_and_id': {'index': 'not_analyzed', 'type': 'string'},                     'surname_and_id': {'index': 'not_analyzed', 'type': 'string'},                     'match': {'index': 'not_analyzed', 'type': 'integer'}                 }}}     } print("creating 'info_main' index...") res = es.index(index="info_main",body=request_body, doc_type='info_m') 

How I am saving to ES:

def chunk_bulk(d):      bulk_data = []      for index, row in d.iterrows():         data_dict = {}         for i in range(len(row)):             data_dict[d.columns[i]] = int(row[i])         op_dict = {             "index": {                 "_index": 'info_main',                 "_type": 'info_m',         }         }         bulk_data.append(op_dict)         bulk_data.append(data_dict)     res = es.bulk(index = 'info_main', body = bulk_data)     return res  sum_ = 0 i = 0 while i <= len(data):     j = i + 9000     d = data[i:j]     i = j     sum_ = sum_ + len(d)     chunk_bulk(d) print(sum_) 

Does anyone know what can cause the problem? If I use only integers and change mappings to an integer, everything works great.

Any help is welcomed. Thanks in advance.