You'll want to guard the function so you don't try to call it on non-X displays (e.g. `emacs -nw`):

    (when window-system
            ;; your code
          )

You might want to access `(display-monitor-attributes-list)` to be more platform portable than the X11 functions (but you'll need to do a bit more work to extract the relevant properties:

    (let* ((dmal (car (display-monitor-attributes-list))) ; first monitor only
           (width (nth 3 (assq 'geometry dmal)))
           (height (nth 4 (assq 'geometry dmal))))
      ;; your code
      )

The test is very specific - you might want to add other, larger screens:

    (and (>= (x-display-pixel-width) 3840)
         (>= (x-display-pixel-width) 2160))

Consider measuring the *pixel pitch* rather than the overall size:

    (< (/ (float (display-mm-height)) (x-display-pixel-width)) 0.1)

Reduce the duplication:

    (setq-default dotspacemacs-default-font
                  (list "Source Code Pro" :size
                        (if (and (eq 3840 (x-display-pixel-width))
                                 (eq 2160 (x-display-pixel-height)))
                            34
                          18)))

Support more than two sizes:


    (setq-default dotspacemacs-default-font
                  (list "Source Code Pro" :size
                        (cond ((<= 3840 (x-display-pixel-width))
                               34)
                              ((<= 1920 (x-display-pixel-width))
                               18)
                              (t
                               12))))